imageDetailsScrollViewController.m 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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. #import "previewLandscapeTopView.h"
  14. #import "previewLandscapeTopMoreView.h"
  15. #import "UIInterface+HXRotation.h"
  16. @interface imageDetailsScrollViewController ()
  17. {
  18. NSMutableArray *imageURLStringsGroup;
  19. }
  20. @property (nonatomic,strong) SDCycleScrollView *curScrollView;
  21. @property(nonatomic,strong) editTypeBottomView*curEditTypeBottomView;
  22. @property(nonatomic,assign) BOOL isPortraitType;//竖屏状态
  23. @property(nonatomic,strong) previewLandscapeTopView*previewLandscapeTopV;
  24. @property(nonatomic,strong) previewLandscapeTopMoreView*previewLandscapeTopMoreV;
  25. @property(nonatomic,assign) BOOL isHideMsgType;//隐藏上下信息
  26. @end
  27. @implementation imageDetailsScrollViewController
  28. - (void)viewDidLoad {
  29. [super viewDidLoad];
  30. // Do any additional setup after loading the view.
  31. [self.toolBar setHidden:YES];
  32. [self.navigationBar setHidden:YES];
  33. [self.navBarBGView setHidden:NO];
  34. self.navBarBGView.backgroundColor = [UIColor clearColor];
  35. self.titleLabel.textColor = [UIColor whiteColor];
  36. [self.backBtn setImage:[UIImage imageNamed:@"icon_white_back"] forState:UIControlStateNormal];
  37. [self.view setBackgroundColor:[UIColor blackColor]];
  38. [self drawAnyView];
  39. _isPortraitType = YES;
  40. }
  41. - (void)drawAnyView
  42. {
  43. // gradient
  44. CAGradientLayer *gl = [CAGradientLayer layer];
  45. gl.frame = CGRectMake(0,0,SCREEN_W,60 + AdaptTabHeight);
  46. gl.startPoint = CGPointMake(0.5, 0);
  47. gl.endPoint = CGPointMake(0.5, 1);
  48. 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];
  49. gl.locations = @[@(0), @(1.0f)];
  50. //[self.layer addSublayer:gl];
  51. [self.navBarBGView.layer insertSublayer:gl atIndex:0];
  52. //横屏的头部
  53. _previewLandscapeTopV = [[previewLandscapeTopView alloc] init];
  54. [self.view addSubview:_previewLandscapeTopV];
  55. _previewLandscapeTopV.hidden = YES;
  56. [_previewLandscapeTopV mas_makeConstraints:^(MASConstraintMaker *make) {
  57. make.left.mas_equalTo(0);
  58. make.right.mas_equalTo(0);
  59. make.top.mas_equalTo(0);
  60. make.height.mas_equalTo(60);
  61. }];
  62. KWeakSelf
  63. _previewLandscapeTopV.didClickButton = ^(NSInteger tag) {
  64. [weakSelf didClickButInLandscapeTopFunBy:tag];
  65. };
  66. }
  67. - (void)viewDidAppear:(BOOL)animated
  68. {
  69. [super viewDidAppear:animated];
  70. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
  71. ksharedAppDelegate.supportScreenRotateType = YES;
  72. //开始生成 设备旋转 通知
  73. [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
  74. //添加 设备旋转 通知
  75. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
  76. }
  77. - (void)viewWillDisappear:(BOOL)animated {
  78. [super viewWillDisappear:animated];
  79. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDarkContent];
  80. ksharedAppDelegate.supportScreenRotateType = NO;
  81. //销毁 设备旋转 通知
  82. [[NSNotificationCenter defaultCenter] removeObserver:self
  83. name:UIDeviceOrientationDidChangeNotification
  84. object:nil];
  85. //结束 设备旋转通知
  86. [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
  87. }
  88. - (BOOL)shouldAutorotate {
  89. return YES;
  90. }
  91. /// 如果不好用则copy VC中 加一下
  92. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  93. return UIInterfaceOrientationMaskAllButUpsideDown;
  94. }
  95. /**屏幕旋转的通知回调*/
  96. - (void)orientChange:(NSNotification *)noti {
  97. UIDeviceOrientation orient = [UIDevice currentDevice].orientation;
  98. switch (orient) {
  99. case UIDeviceOrientationPortrait:
  100. NSLog(@"竖直屏幕");
  101. if(!_isPortraitType){
  102. [self screenLandscapeToPortraitFun];
  103. }
  104. break;
  105. case UIDeviceOrientationLandscapeLeft:
  106. NSLog(@"手机左转");
  107. if(_isPortraitType){
  108. [self screenPortraitToLandscapeFun];
  109. }
  110. break;
  111. case UIDeviceOrientationPortraitUpsideDown:
  112. // NSLog(@"手机竖直");
  113. break;
  114. case UIDeviceOrientationLandscapeRight:
  115. NSLog(@"手机右转");
  116. if(_isPortraitType){
  117. [self screenPortraitToLandscapeFun];
  118. }
  119. break;
  120. case UIDeviceOrientationUnknown:
  121. //NSLog(@"未知");
  122. break;
  123. case UIDeviceOrientationFaceUp:
  124. //NSLog(@"手机屏幕朝上");
  125. break;
  126. case UIDeviceOrientationFaceDown:
  127. //NSLog(@"手机屏幕朝下");
  128. break;
  129. default:
  130. break;
  131. }
  132. }
  133. #pragma mark 竖屏转横屏
  134. - (void)screenPortraitToLandscapeFun{
  135. _isPortraitType = NO;
  136. _curEditTypeBottomView.hidden = YES;
  137. self.navBarBGView.hidden = YES;
  138. _previewLandscapeTopV.hidden = NO;
  139. [self didClickScreenFun:NO];
  140. [_previewLandscapeTopV mas_remakeConstraints:^(MASConstraintMaker *make) {
  141. make.left.mas_equalTo(0);
  142. make.right.mas_equalTo(0);
  143. make.top.mas_equalTo(0);
  144. make.height.mas_equalTo(60);
  145. }];
  146. }
  147. #pragma mark 横屏转竖屏
  148. - (void)screenLandscapeToPortraitFun{
  149. _isPortraitType = YES;
  150. _curEditTypeBottomView.hidden = NO;
  151. self.navBarBGView.hidden = NO;
  152. _previewLandscapeTopV.hidden = YES;
  153. [self didClickScreenFun:NO];
  154. [self deletePreviewLandscapeTopMoreViewFun];
  155. }
  156. #pragma mark 用户点击分享
  157. - (void)gotoShareViewFun
  158. {
  159. editShareView *editShareV = [[editShareView alloc] init];
  160. NASFilePicDataArrModel *dataModel = _totalDataArr[_index];
  161. editShareV.didSelectListArr = [NSMutableArray arrayWithArray:@[dataModel]];
  162. editShareV.shareFileType = @"2";
  163. [self.view addSubview:editShareV];
  164. [editShareV mas_makeConstraints:^(MASConstraintMaker *make) {
  165. make.left.mas_equalTo(0);
  166. make.right.mas_equalTo(0);
  167. make.bottom.mas_equalTo(0);
  168. make.top.mas_equalTo(0);
  169. }];
  170. }
  171. - (void)setTotalDataArr:(NSMutableArray *)totalDataArr
  172. {
  173. _totalDataArr = totalDataArr;
  174. imageURLStringsGroup = [NSMutableArray new];
  175. for (NASFilePicDataArrModel*dataModel in _totalDataArr) {
  176. NSString * URLString = [[NSString alloc] initWithFormat:@"%@getFile?path=%@",ksharedAppDelegate.NASFileByBoxService,dataModel.path];
  177. URLString = [URLString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  178. [imageURLStringsGroup addObject:URLString];
  179. }
  180. //HLog(@"URLString:\n%@",imageURLStringsGroup);
  181. _curScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero imageURLStringsGroup:imageURLStringsGroup];
  182. _curScrollView.autoScroll = NO;
  183. _curScrollView.infiniteLoop = NO;
  184. _curScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFit;
  185. //_curScrollView.placeholderImage = [UIImage imageNamed:@"uploadFile_image"];
  186. //[self.view addSubview:_curScrollView];
  187. [self.view insertSubview:_curScrollView belowSubview:self.navBarBGView];
  188. _curScrollView.backgroundColor = [UIColor blackColor];
  189. [_curScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
  190. make.left.mas_equalTo(0);
  191. make.right.mas_equalTo(0);
  192. //make.top.equalTo(self.navBarBGView.mas_bottom).offset(0);
  193. make.top.mas_equalTo(0);
  194. //make.bottom.mas_equalTo(-(60+ AdaptTabHeight));
  195. make.bottom.mas_equalTo(0);
  196. }];
  197. KWeakSelf
  198. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  199. [self->_curScrollView makeScrollViewScrollToIndex:self->_index];
  200. [weakSelf setTitleLabelTextFunBy:self->_index];
  201. [weakSelf cycleScrollViewDidScrollToIndex:self->_index];
  202. self->_curScrollView.hidden = NO;
  203. });
  204. _curScrollView.itemDidScrollOperationBlock = ^(NSInteger currentIndex) {
  205. weakSelf.index = currentIndex;
  206. [weakSelf setTitleLabelTextFunBy:currentIndex];
  207. [weakSelf cycleScrollViewDidScrollToIndex:currentIndex];
  208. };
  209. _curScrollView.clickItemOperationBlock = ^(NSInteger currentIndex) {
  210. self->_isHideMsgType = !self->_isHideMsgType;
  211. [weakSelf didClickScreenFun:self->_isHideMsgType];
  212. };
  213. _curEditTypeBottomView = [[editTypeBottomView alloc] init];
  214. _curEditTypeBottomView.isBlackType = YES;
  215. [self.view addSubview:_curEditTypeBottomView];
  216. //_curEditTypeBottomView.hidden = YES;
  217. [_curEditTypeBottomView mas_makeConstraints:^(MASConstraintMaker *make) {
  218. make.left.mas_equalTo(0);
  219. make.right.mas_equalTo(0);
  220. make.bottom.mas_equalTo(0);
  221. make.height.mas_equalTo(60 + AdaptTabHeight);
  222. }];
  223. //KWeakSelf
  224. #pragma mark 编辑状态的 下载 分享 删除 响应事件
  225. _curEditTypeBottomView.didClickButtonFun = ^(NSInteger tag) {
  226. if(tag==1){
  227. //[[iToast makeText:@"点击下载"] show];
  228. [weakSelf gotoDownLoadFileFun];
  229. }
  230. else if(tag==2){
  231. [weakSelf gotoShareViewFun];
  232. }
  233. else if(tag==3){
  234. //[[iToast makeText:@"点击删除"] show];
  235. [weakSelf showDeleteAlearViewFun];
  236. }
  237. };
  238. }
  239. - (void)setTitleLabelTextFunBy:(NSInteger)index
  240. {
  241. if(index >=0 && index < _totalDataArr.count){
  242. NASFilePicDataArrModel *dataModel = _totalDataArr[index];
  243. self.titleLabel.text = dataModel.name;
  244. _previewLandscapeTopV.titleLabel.text = dataModel.name;
  245. }
  246. }
  247. #pragma mark 删除图片
  248. - (void)showDeleteAlearViewFun
  249. {
  250. NSString *titleStr = NSLocalizedString(@"delete_file_title_msg",nil);
  251. NSString *tipStr = NSLocalizedString(@"delete_file_tip_msg",nil);
  252. KWeakSelf
  253. ComontAlretViewController *curAlretVC= [[ComontAlretViewController alloc] initWithTiTle:titleStr
  254. msg:tipStr
  255. imageStr:nil
  256. cancelTitle:NSLocalizedString(@"other_cancel",nil)
  257. okTitle:NSLocalizedString(@"other_confirm",nil) isOkBtnHighlight:YES
  258. didClickOk:^{
  259. [weakSelf delFileListFun];
  260. } didClickCancel:^{
  261. }];
  262. curAlretVC.modalPresentationStyle = UIModalPresentationCustom;
  263. [self presentViewController:curAlretVC animated:YES completion:^{
  264. curAlretVC.view.superview.backgroundColor = [UIColor clearColor];
  265. }];
  266. }
  267. #pragma mark 删除文件数据
  268. - (void)delFileListFun
  269. {
  270. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  271. if(_index >=0 && _index < _totalDataArr.count){
  272. NASFilePicDataArrModel *dataModel = _totalDataArr[_index];
  273. NSArray *pathArr = @[dataModel.path];
  274. //NSArray *pathArr = @[dataModel.path,dataModel.path];
  275. [paraDict setValue:pathArr forKey:@"path"];
  276. }
  277. [self showNewIndicatorWithCanBack:YES canTouch:NO];
  278. //NSString*code = [[NSString alloc] initWithFormat:@"delFile?path=%@",paraDict[@"path"]]; //delFile?path=[/storage/emulated/0/Download/IMG_6464.HEIC]
  279. KWeakSelf //@"delFile"
  280. [[netWorkManager shareInstance] cloudPhonePostCallBackCode:@"delFile" Parameters:paraDict success:^(id _Nonnull responseObject) {
  281. [weakSelf removeNewIndicator];
  282. SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  283. if(model && model.status == 0){
  284. [[iToast makeText:NSLocalizedString(@"delete_file_suc_msg",nil)] show];
  285. if(weakSelf.didNeedToRegetDataFun){
  286. weakSelf.didNeedToRegetDataFun();
  287. }
  288. [weakSelf.navigationController popViewControllerAnimated:YES];
  289. }
  290. else{
  291. }
  292. } failure:^(NSError * _Nonnull error) {
  293. [weakSelf removeNewIndicator];
  294. }];
  295. }
  296. - (void)gotoDownLoadFileFun
  297. {
  298. if(_index >=0 && _index < _totalDataArr.count){
  299. NASFilePicDataArrModel *dataModel = _totalDataArr[_index];
  300. couldPhoneFileModel* fileModel = [couldPhoneFileModel new];
  301. fileModel.fileType = @".jpg";
  302. fileModel.path = dataModel.path;
  303. fileModel.name = dataModel.name;
  304. fileModel.length = dataModel.size;
  305. NSMutableArray *arr = [NSMutableArray new];
  306. [arr addObject:fileModel];
  307. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  308. [self.navigationController pushViewController:vc animated:YES];
  309. vc.isDownloadingType = YES;
  310. [vc gotoDownloadFile:arr];
  311. }
  312. }
  313. - (void)setCanShareType:(BOOL)canShareType
  314. {
  315. _canShareType = canShareType;
  316. [_curEditTypeBottomView setCanShaewFunBy:canShareType];
  317. }
  318. #pragma mark 图片滑动
  319. - (void)cycleScrollViewDidScrollToIndex:(NSInteger)index{
  320. if(index >=0 && index < _totalDataArr.count){
  321. NASFilePicDataArrModel *dataModel = _totalDataArr[index];
  322. lastFileModel *lastFileMod = [lastFileModel new];
  323. lastFileMod.path = dataModel.path;
  324. lastFileMod.name = dataModel.name;
  325. lastFileMod.time = dataModel.time;
  326. lastFileMod.size = dataModel.size;
  327. lastFileMod.duration = dataModel.duration;
  328. lastFileMod.type = @"jpg";
  329. lastFileMod.lastPreTime = [iTools getNowTimeStamp];
  330. [[lastFileManager shareManager] saveFileInfoWith:lastFileMod with:dataModel.path];
  331. }
  332. }
  333. #pragma mark 横屏时点击顶部按钮
  334. - (void)didClickButInLandscapeTopFunBy:(NSInteger)tag
  335. {
  336. if(tag == 1){
  337. [self backBtnPressed];
  338. }
  339. else if(tag == 2){
  340. [self showPreviewLandscapeTopMoreViewFun];
  341. }
  342. else if(tag == 3){//分享
  343. [self gotoShareViewFun];
  344. }
  345. }
  346. #pragma mark 删除横屏的 more
  347. - (void)deletePreviewLandscapeTopMoreViewFun
  348. {
  349. [_previewLandscapeTopMoreV removeFromSuperview];
  350. _previewLandscapeTopMoreV = nil;
  351. }
  352. #pragma mark 点开了横屏的 more
  353. - (void)showPreviewLandscapeTopMoreViewFun
  354. {
  355. [self deletePreviewLandscapeTopMoreViewFun];
  356. _previewLandscapeTopMoreV = [[previewLandscapeTopMoreView alloc] init];
  357. [self.view addSubview:_previewLandscapeTopMoreV];
  358. [_previewLandscapeTopMoreV mas_makeConstraints:^(MASConstraintMaker *make) {
  359. make.left.mas_equalTo(0);
  360. make.right.mas_equalTo(0);
  361. make.top.mas_equalTo(0);
  362. make.bottom.mas_equalTo(0);
  363. }];
  364. KWeakSelf
  365. _previewLandscapeTopMoreV.didClickButtonFun = ^(NSInteger tag) {
  366. if(tag==10){
  367. //[[iToast makeText:@"点击下载"] show];
  368. //切换到竖屏
  369. [weakSelf hx_rotateToInterfaceOrientation:UIInterfaceOrientationPortrait];
  370. [weakSelf screenLandscapeToPortraitFun];
  371. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  372. [weakSelf gotoDownLoadFileFun];
  373. });
  374. }
  375. else if(tag==11){
  376. //[[iToast makeText:@"点击删除"] show];
  377. [weakSelf showDeleteAlearViewFun];
  378. }
  379. };
  380. }
  381. #pragma mark 点开了屏幕
  382. - (void)didClickScreenFun:(BOOL)isHideMsgType
  383. {
  384. _isHideMsgType = isHideMsgType;
  385. if(isHideMsgType){//处理隐藏
  386. if(_isPortraitType){
  387. CGRect BottomViewRect = _curEditTypeBottomView.frame;
  388. CGRect fixBottomViewRect = CGRectMake(BottomViewRect.origin.x, BottomViewRect.origin.y + BottomViewRect.size.height, BottomViewRect.size.width, BottomViewRect.size.height);
  389. CGRect navBarBGViewRect = self.navBarBGView.frame;
  390. CGRect fixNavBarBGViewRect = CGRectMake(navBarBGViewRect.origin.x, navBarBGViewRect.origin.y - navBarBGViewRect.size.height, navBarBGViewRect.size.width, navBarBGViewRect.size.height);
  391. [UIView animateWithDuration:0.3 animations:^{
  392. self->_curEditTypeBottomView.frame = fixBottomViewRect;
  393. self.navBarBGView.frame = fixNavBarBGViewRect;
  394. } completion:^(BOOL finished) {
  395. self->_curEditTypeBottomView.hidden = YES;
  396. self.navBarBGView.hidden = YES;
  397. //frame 还原
  398. self->_curEditTypeBottomView.frame = BottomViewRect;
  399. self.navBarBGView.frame = navBarBGViewRect;
  400. }];
  401. }
  402. else{
  403. CGRect TopViewRect = _previewLandscapeTopV.frame;
  404. CGRect fixTopViewRect = CGRectMake(TopViewRect.origin.x, TopViewRect.origin.y - TopViewRect.size.height, TopViewRect.size.width, TopViewRect.size.height);
  405. [UIView animateWithDuration:0.3 animations:^{
  406. self->_previewLandscapeTopV.frame = fixTopViewRect;
  407. } completion:^(BOOL finished) {
  408. self->_previewLandscapeTopV.hidden = YES;
  409. //frame 还原
  410. self->_previewLandscapeTopV.frame = TopViewRect;
  411. }];
  412. }
  413. }
  414. else{//处理显示
  415. if(_isPortraitType){
  416. CGRect BottomViewRect = _curEditTypeBottomView.frame;
  417. CGRect fixBottomViewRect = CGRectMake(BottomViewRect.origin.x, BottomViewRect.origin.y + BottomViewRect.size.height, BottomViewRect.size.width, BottomViewRect.size.height);
  418. CGRect navBarBGViewRect = self.navBarBGView.frame;
  419. CGRect fixNavBarBGViewRect = CGRectMake(navBarBGViewRect.origin.x, navBarBGViewRect.origin.y - navBarBGViewRect.size.height, navBarBGViewRect.size.width, navBarBGViewRect.size.height);
  420. self->_curEditTypeBottomView.frame = fixBottomViewRect;
  421. self.navBarBGView.frame = fixNavBarBGViewRect;
  422. [UIView animateWithDuration:0.3 animations:^{
  423. //frame 还原
  424. self->_curEditTypeBottomView.frame = BottomViewRect;
  425. self.navBarBGView.frame = navBarBGViewRect;
  426. } completion:^(BOOL finished) {
  427. self->_curEditTypeBottomView.hidden = NO;
  428. self.navBarBGView.hidden = NO;
  429. }];
  430. }
  431. else{
  432. _previewLandscapeTopV.hidden = NO;
  433. CGRect topViewRect = _previewLandscapeTopV.frame;
  434. CGRect fixTopViewRect = CGRectMake(topViewRect.origin.x, topViewRect.origin.y - topViewRect.size.height, topViewRect.size.width, topViewRect.size.height);
  435. self->_previewLandscapeTopV.frame = fixTopViewRect;
  436. [UIView animateWithDuration:0.3 animations:^{
  437. //frame 还原
  438. self->_previewLandscapeTopV.frame = topViewRect;
  439. } completion:^(BOOL finished) {
  440. self->_previewLandscapeTopV.hidden = NO;
  441. }];
  442. }
  443. }
  444. }
  445. @end