imageDetailsScrollViewController.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. //
  2. // imageDetailsScrollViewController.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/5/16.
  6. //
  7. #import "imageDetailsScrollViewController.h"
  8. #import <SDCycleScrollView/SDCycleScrollView.h>
  9. #import "editTypeBottomView.h"
  10. #import "editShareView.h"
  11. #import "NASFilePicModel.h"
  12. #import "uploadFileRecordViewController.h"
  13. @interface imageDetailsScrollViewController ()
  14. {
  15. NSMutableArray *imageURLStringsGroup;
  16. }
  17. @property (nonatomic,strong) SDCycleScrollView *curScrollView;
  18. @property(nonatomic,strong) editTypeBottomView*curEditTypeBottomView;
  19. @property(nonatomic,assign) BOOL isPortraitType;//竖屏状态
  20. @end
  21. @implementation imageDetailsScrollViewController
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. // Do any additional setup after loading the view.
  25. [self.toolBar setHidden:YES];
  26. [self.navigationBar setHidden:YES];
  27. [self.navBarBGView setHidden:NO];
  28. self.navBarBGView.backgroundColor = [UIColor clearColor];
  29. self.titleLabel.textColor = [UIColor whiteColor];
  30. [self.backBtn setImage:[UIImage imageNamed:@"icon_white_back"] forState:UIControlStateNormal];
  31. [self.view setBackgroundColor:[UIColor blackColor]];
  32. [self drawAnyView];
  33. _isPortraitType = YES;
  34. }
  35. - (void)drawAnyView
  36. {
  37. // gradient
  38. CAGradientLayer *gl = [CAGradientLayer layer];
  39. gl.frame = CGRectMake(0,0,SCREEN_W,60 + AdaptTabHeight);
  40. gl.startPoint = CGPointMake(0.5, 0);
  41. gl.endPoint = CGPointMake(0.5, 1);
  42. gl.colors = @[(__bridge id)[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1.0].CGColor, (__bridge id)[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.0].CGColor];
  43. gl.locations = @[@(0), @(1.0f)];
  44. //[self.layer addSublayer:gl];
  45. [self.navBarBGView.layer insertSublayer:gl atIndex:0];
  46. }
  47. - (void)viewDidAppear:(BOOL)animated
  48. {
  49. [super viewDidAppear:animated];
  50. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
  51. ksharedAppDelegate.supportScreenRotateType = YES;
  52. //开始生成 设备旋转 通知
  53. [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
  54. //添加 设备旋转 通知
  55. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
  56. }
  57. - (void)viewWillDisappear:(BOOL)animated {
  58. [super viewWillDisappear:animated];
  59. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDarkContent];
  60. ksharedAppDelegate.supportScreenRotateType = NO;
  61. //销毁 设备旋转 通知
  62. [[NSNotificationCenter defaultCenter] removeObserver:self
  63. name:UIDeviceOrientationDidChangeNotification
  64. object:nil];
  65. //结束 设备旋转通知
  66. [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
  67. }
  68. - (BOOL)shouldAutorotate {
  69. return YES;
  70. }
  71. /// 如果不好用则copy VC中 加一下
  72. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  73. return UIInterfaceOrientationMaskAllButUpsideDown;
  74. }
  75. /**屏幕旋转的通知回调*/
  76. - (void)orientChange:(NSNotification *)noti {
  77. UIDeviceOrientation orient = [UIDevice currentDevice].orientation;
  78. switch (orient) {
  79. case UIDeviceOrientationPortrait:
  80. NSLog(@"竖直屏幕");
  81. if(!_isPortraitType){
  82. [self screenLandscapeToPortraitFun];
  83. }
  84. break;
  85. case UIDeviceOrientationLandscapeLeft:
  86. NSLog(@"手机左转");
  87. if(_isPortraitType){
  88. [self screenPortraitToLandscapeFun];
  89. }
  90. break;
  91. case UIDeviceOrientationPortraitUpsideDown:
  92. // NSLog(@"手机竖直");
  93. break;
  94. case UIDeviceOrientationLandscapeRight:
  95. NSLog(@"手机右转");
  96. if(_isPortraitType){
  97. [self screenPortraitToLandscapeFun];
  98. }
  99. break;
  100. case UIDeviceOrientationUnknown:
  101. //NSLog(@"未知");
  102. break;
  103. case UIDeviceOrientationFaceUp:
  104. //NSLog(@"手机屏幕朝上");
  105. break;
  106. case UIDeviceOrientationFaceDown:
  107. //NSLog(@"手机屏幕朝下");
  108. break;
  109. default:
  110. break;
  111. }
  112. }
  113. #pragma mark 竖屏转横屏
  114. - (void)screenPortraitToLandscapeFun{
  115. _isPortraitType = NO;
  116. _curEditTypeBottomView.hidden = YES;
  117. self.navBarBGView.hidden = YES;
  118. }
  119. #pragma mark 横屏转竖屏
  120. - (void)screenLandscapeToPortraitFun{
  121. _isPortraitType = YES;
  122. _curEditTypeBottomView.hidden = NO;
  123. self.navBarBGView.hidden = NO;
  124. }
  125. #pragma mark 用户点击分享
  126. - (void)gotoShareViewFun
  127. {
  128. editShareView *editShareV = [[editShareView alloc] init];
  129. NASFilePicDataArrModel *dataModel = _totalDataArr[_index];
  130. editShareV.didSelectListArr = [NSMutableArray arrayWithArray:@[dataModel]];
  131. editShareV.shareFileType = @"2";
  132. [self.view addSubview:editShareV];
  133. [editShareV mas_makeConstraints:^(MASConstraintMaker *make) {
  134. make.left.mas_equalTo(0);
  135. make.right.mas_equalTo(0);
  136. make.bottom.mas_equalTo(0);
  137. make.top.mas_equalTo(0);
  138. }];
  139. }
  140. - (void)setTotalDataArr:(NSMutableArray *)totalDataArr
  141. {
  142. _totalDataArr = totalDataArr;
  143. imageURLStringsGroup = [NSMutableArray new];
  144. for (NASFilePicDataArrModel*dataModel in _totalDataArr) {
  145. NSString * URLString = [[NSString alloc] initWithFormat:@"%@getFile?path=%@",ksharedAppDelegate.NASFileByBoxService,dataModel.path];
  146. URLString = [URLString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  147. [imageURLStringsGroup addObject:URLString];
  148. }
  149. //HLog(@"URLString:\n%@",imageURLStringsGroup);
  150. _curScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero imageURLStringsGroup:imageURLStringsGroup];
  151. _curScrollView.autoScroll = NO;
  152. _curScrollView.infiniteLoop = NO;
  153. _curScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFit;
  154. //_curScrollView.placeholderImage = [UIImage imageNamed:@"uploadFile_image"];
  155. //[self.view addSubview:_curScrollView];
  156. [self.view insertSubview:_curScrollView belowSubview:self.navBarBGView];
  157. _curScrollView.backgroundColor = [UIColor blackColor];
  158. [_curScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
  159. make.left.mas_equalTo(0);
  160. make.right.mas_equalTo(0);
  161. //make.top.equalTo(self.navBarBGView.mas_bottom).offset(0);
  162. make.top.mas_equalTo(0);
  163. //make.bottom.mas_equalTo(-(60+ AdaptTabHeight));
  164. make.bottom.mas_equalTo(0);
  165. }];
  166. KWeakSelf
  167. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  168. [self->_curScrollView makeScrollViewScrollToIndex:self->_index];
  169. [weakSelf setTitleLabelTextFunBy:self->_index];
  170. [weakSelf cycleScrollViewDidScrollToIndex:self->_index];
  171. self->_curScrollView.hidden = NO;
  172. });
  173. _curScrollView.itemDidScrollOperationBlock = ^(NSInteger currentIndex) {
  174. weakSelf.index = currentIndex;
  175. [weakSelf setTitleLabelTextFunBy:currentIndex];
  176. [weakSelf cycleScrollViewDidScrollToIndex:currentIndex];
  177. };
  178. _curEditTypeBottomView = [[editTypeBottomView alloc] init];
  179. _curEditTypeBottomView.isBlackType = YES;
  180. [self.view addSubview:_curEditTypeBottomView];
  181. //_curEditTypeBottomView.hidden = YES;
  182. [_curEditTypeBottomView mas_makeConstraints:^(MASConstraintMaker *make) {
  183. make.left.mas_equalTo(0);
  184. make.right.mas_equalTo(0);
  185. make.bottom.mas_equalTo(0);
  186. make.height.mas_equalTo(60 + AdaptTabHeight);
  187. }];
  188. //KWeakSelf
  189. #pragma mark 编辑状态的 下载 分享 删除 响应事件
  190. _curEditTypeBottomView.didClickButtonFun = ^(NSInteger tag) {
  191. if(tag==1){
  192. //[[iToast makeText:@"点击下载"] show];
  193. [weakSelf gotoDownLoadFileFun];
  194. }
  195. else if(tag==2){
  196. [weakSelf gotoShareViewFun];
  197. }
  198. else if(tag==3){
  199. //[[iToast makeText:@"点击删除"] show];
  200. [weakSelf showDeleteAlearViewFun];
  201. }
  202. };
  203. }
  204. - (void)setTitleLabelTextFunBy:(NSInteger)index
  205. {
  206. if(index >=0 && index < _totalDataArr.count){
  207. NASFilePicDataArrModel *dataModel = _totalDataArr[index];
  208. self.titleLabel.text = dataModel.name;
  209. }
  210. }
  211. #pragma mark 删除图片
  212. - (void)showDeleteAlearViewFun
  213. {
  214. NSString *titleStr = NSLocalizedString(@"delete_file_title_msg",nil);
  215. NSString *tipStr = NSLocalizedString(@"delete_file_tip_msg",nil);
  216. KWeakSelf
  217. ComontAlretViewController *curAlretVC= [[ComontAlretViewController alloc] initWithTiTle:titleStr
  218. msg:tipStr
  219. imageStr:nil
  220. cancelTitle:NSLocalizedString(@"other_cancel",nil)
  221. okTitle:NSLocalizedString(@"other_confirm",nil) isOkBtnHighlight:YES
  222. didClickOk:^{
  223. [weakSelf delFileListFun];
  224. } didClickCancel:^{
  225. }];
  226. curAlretVC.modalPresentationStyle = UIModalPresentationCustom;
  227. [self presentViewController:curAlretVC animated:YES completion:^{
  228. curAlretVC.view.superview.backgroundColor = [UIColor clearColor];
  229. }];
  230. }
  231. #pragma mark 删除文件数据
  232. - (void)delFileListFun
  233. {
  234. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  235. if(_index >=0 && _index < _totalDataArr.count){
  236. NASFilePicDataArrModel *dataModel = _totalDataArr[_index];
  237. NSArray *pathArr = @[dataModel.path];
  238. //NSArray *pathArr = @[dataModel.path,dataModel.path];
  239. [paraDict setValue:pathArr forKey:@"path"];
  240. }
  241. [self showNewIndicatorWithCanBack:YES canTouch:NO];
  242. //NSString*code = [[NSString alloc] initWithFormat:@"delFile?path=%@",paraDict[@"path"]]; //delFile?path=[/storage/emulated/0/Download/IMG_6464.HEIC]
  243. KWeakSelf //@"delFile"
  244. [[netWorkManager shareInstance] cloudPhonePostCallBackCode:@"delFile" Parameters:paraDict success:^(id _Nonnull responseObject) {
  245. [weakSelf removeNewIndicator];
  246. SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  247. if(model && model.status == 0){
  248. [[iToast makeText:NSLocalizedString(@"delete_file_suc_msg",nil)] show];
  249. if(weakSelf.didNeedToRegetDataFun){
  250. weakSelf.didNeedToRegetDataFun();
  251. }
  252. [weakSelf.navigationController popViewControllerAnimated:YES];
  253. }
  254. else{
  255. }
  256. } failure:^(NSError * _Nonnull error) {
  257. [weakSelf removeNewIndicator];
  258. }];
  259. }
  260. - (void)gotoDownLoadFileFun
  261. {
  262. if(_index >=0 && _index < _totalDataArr.count){
  263. NASFilePicDataArrModel *dataModel = _totalDataArr[_index];
  264. couldPhoneFileModel* fileModel = [couldPhoneFileModel new];
  265. fileModel.fileType = @".jpg";
  266. fileModel.path = dataModel.path;
  267. fileModel.name = dataModel.name;
  268. fileModel.length = dataModel.size;
  269. NSMutableArray *arr = [NSMutableArray new];
  270. [arr addObject:fileModel];
  271. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  272. [self.navigationController pushViewController:vc animated:YES];
  273. vc.isDownloadingType = YES;
  274. [vc gotoDownloadFile:arr];
  275. }
  276. }
  277. - (void)setCanShareType:(BOOL)canShareType
  278. {
  279. _canShareType = canShareType;
  280. [_curEditTypeBottomView setCanShaewFunBy:canShareType];
  281. }
  282. #pragma mark 图片滑动
  283. - (void)cycleScrollViewDidScrollToIndex:(NSInteger)index{
  284. if(index >=0 && index < _totalDataArr.count){
  285. NASFilePicDataArrModel *dataModel = _totalDataArr[index];
  286. lastFileModel *lastFileMod = [lastFileModel new];
  287. lastFileMod.path = dataModel.path;
  288. lastFileMod.name = dataModel.name;
  289. lastFileMod.time = dataModel.time;
  290. lastFileMod.size = dataModel.size;
  291. lastFileMod.duration = dataModel.duration;
  292. lastFileMod.type = @"jpg";
  293. lastFileMod.lastPreTime = [iTools getNowTimeStamp];
  294. [[lastFileManager shareManager] saveFileInfoWith:lastFileMod with:dataModel.path];
  295. }
  296. }
  297. @end