// // imageDetailsScrollViewController.m // Private-X // // Created by xd h on 2024/5/16. // #import "imageDetailsScrollViewController.h" #import #import "editTypeBottomView.h" #import "editShareView.h" #import "NASFilePicModel.h" #import "uploadFileRecordViewController.h" #import "previewLandscapeTopView.h" #import "previewLandscapeTopMoreView.h" #import "UIInterface+HXRotation.h" @interface imageDetailsScrollViewController () { NSMutableArray *imageURLStringsGroup; } @property (nonatomic,strong) SDCycleScrollView *curScrollView; @property(nonatomic,strong) editTypeBottomView*curEditTypeBottomView; @property(nonatomic,assign) BOOL isPortraitType;//竖屏状态 @property(nonatomic,strong) previewLandscapeTopView*previewLandscapeTopV; @property(nonatomic,strong) previewLandscapeTopMoreView*previewLandscapeTopMoreV; @property(nonatomic,strong) editShareView *editShareV; @property(nonatomic,assign) BOOL isHideMsgType;//隐藏上下信息 @end @implementation imageDetailsScrollViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self.toolBar setHidden:YES]; [self.navigationBar setHidden:YES]; [self.navBarBGView setHidden:NO]; self.navBarBGView.backgroundColor = [UIColor clearColor]; self.titleLabel.textColor = [UIColor whiteColor]; [self.backBtn setImage:[UIImage imageNamed:@"icon_white_back"] forState:UIControlStateNormal]; [self.view setBackgroundColor:[UIColor blackColor]]; [self drawAnyView]; _isPortraitType = YES; //数据埋点 [[netWorkManager shareInstance] DataEmbeddingPointBy:4 withEventValue:@"Image_preview"]; } - (void)drawAnyView { // gradient CAGradientLayer *gl = [CAGradientLayer layer]; gl.frame = CGRectMake(0,0,SCREEN_W,60 + AdaptTabHeight); gl.startPoint = CGPointMake(0.5, 0); gl.endPoint = CGPointMake(0.5, 1); 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]; gl.locations = @[@(0), @(1.0f)]; //[self.layer addSublayer:gl]; [self.navBarBGView.layer insertSublayer:gl atIndex:0]; //横屏的头部 _previewLandscapeTopV = [[previewLandscapeTopView alloc] init]; [self.view addSubview:_previewLandscapeTopV]; _previewLandscapeTopV.hidden = YES; [_previewLandscapeTopV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.top.mas_equalTo(0); make.height.mas_equalTo(60); }]; KWeakSelf _previewLandscapeTopV.didClickButton = ^(NSInteger tag) { [weakSelf didClickButInLandscapeTopFunBy:tag]; }; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; ksharedAppDelegate.supportScreenRotateType = YES; //开始生成 设备旋转 通知 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; //添加 设备旋转 通知 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientChange:) name:UIDeviceOrientationDidChangeNotification object:nil]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDarkContent]; ksharedAppDelegate.supportScreenRotateType = NO; //销毁 设备旋转 通知 [[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil]; //结束 设备旋转通知 [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; //切换到竖屏 [self hx_rotateToInterfaceOrientation:UIInterfaceOrientationPortrait]; } - (BOOL)shouldAutorotate { return YES; } /// 如果不好用则copy VC中 加一下 - (UIInterfaceOrientationMask)supportedInterfaceOrientations { return UIInterfaceOrientationMaskAllButUpsideDown; } /**屏幕旋转的通知回调*/ - (void)orientChange:(NSNotification *)noti { UIDeviceOrientation orient = [UIDevice currentDevice].orientation; switch (orient) { case UIDeviceOrientationPortrait: NSLog(@"竖直屏幕"); if(!_isPortraitType){ [self screenLandscapeToPortraitFun]; } break; case UIDeviceOrientationLandscapeLeft: NSLog(@"手机左转"); if(_isPortraitType){ [self screenPortraitToLandscapeFun]; } break; case UIDeviceOrientationPortraitUpsideDown: // NSLog(@"手机竖直"); break; case UIDeviceOrientationLandscapeRight: NSLog(@"手机右转"); if(_isPortraitType){ [self screenPortraitToLandscapeFun]; } break; case UIDeviceOrientationUnknown: //NSLog(@"未知"); break; case UIDeviceOrientationFaceUp: //NSLog(@"手机屏幕朝上"); break; case UIDeviceOrientationFaceDown: //NSLog(@"手机屏幕朝下"); break; default: break; } } #pragma mark 竖屏转横屏 - (void)screenPortraitToLandscapeFun{ _isPortraitType = NO; _curEditTypeBottomView.hidden = YES; self.navBarBGView.hidden = YES; _previewLandscapeTopV.hidden = NO; [self didClickScreenFun:NO]; [_previewLandscapeTopV mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.top.mas_equalTo(0); make.height.mas_equalTo(60); }]; if(_editShareV){ _editShareV.isPortraitType = _isPortraitType; } if(_editShareV.secretShareView) { _editShareV.secretShareView.isPortraitType = _isPortraitType; } [self handleScreenRotateFun]; } #pragma mark 屏幕旋转 图片偏移问题 - (void)handleScreenRotateFun { [_curScrollView mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0.0); make.right.mas_equalTo(0.0); make.top.mas_equalTo(0.0); make.bottom.mas_equalTo(0.0); }]; [_curScrollView.mainView mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0.0); make.right.mas_equalTo(0.0); make.top.mas_equalTo(0.0); make.bottom.mas_equalTo(0.0); }]; KWeakSelf dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.05 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ //[self->_curScrollView adjustWhenControllerViewWillAppera]; [weakSelf handleScreenRotateSecondFun]; }); } - (void)handleScreenRotateSecondFun { NSInteger curIndex = _index; HLog(@"curIndexcurIndex 222:%ld",curIndex) [_curScrollView removeFromSuperview]; self.totalDataArr = _totalDataArr; [self->_curScrollView makeScrollViewScrollToIndex:curIndex]; } #pragma mark 横屏转竖屏 - (void)screenLandscapeToPortraitFun{ _isPortraitType = YES; _curEditTypeBottomView.hidden = NO; self.navBarBGView.hidden = NO; _previewLandscapeTopV.hidden = YES; [self didClickScreenFun:NO]; if(_editShareV){ _editShareV.isPortraitType = _isPortraitType; } if(_editShareV.secretShareView) { _editShareV.secretShareView.isPortraitType = _isPortraitType; } [self handleScreenRotateFun]; } #pragma mark 用户点击分享 - (void)gotoShareViewFun { _editShareV = [[editShareView alloc] init]; NASFilePicDataArrModel *dataModel = _totalDataArr[_index]; _editShareV.didSelectListArr = [NSMutableArray arrayWithArray:@[dataModel]]; _editShareV.shareFileType = @"2"; [self.view addSubview:_editShareV]; _editShareV.isPortraitType = _isPortraitType; [_editShareV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.bottom.mas_equalTo(0); make.top.mas_equalTo(0); }]; KWeakSelf _editShareV.didClickCloseFun = ^{ [weakSelf clearShareAboutViewFun]; }; } #pragma mark 清理分享相关页面 - (void)clearShareAboutViewFun { if(_editShareV.secretShareView){ _editShareV.secretShareView = nil; } _editShareV = nil; } - (void)setTotalDataArr:(NSMutableArray *)totalDataArr { _totalDataArr = totalDataArr; imageURLStringsGroup = [NSMutableArray new]; for (NASFilePicDataArrModel*dataModel in _totalDataArr) { NSString * URLString = [[NSString alloc] initWithFormat:@"%@getFile?path=%@",ksharedAppDelegate.NASFileByBoxService,dataModel.path]; URLString = [URLString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; [imageURLStringsGroup addObject:URLString]; } //HLog(@"URLString:\n%@",imageURLStringsGroup); if(_curScrollView){ [_curScrollView removeFromSuperview]; _curScrollView = nil; } _curScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero imageURLStringsGroup:imageURLStringsGroup]; _curScrollView.autoScroll = NO; _curScrollView.infiniteLoop = NO; _curScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFit; //_curScrollView.placeholderImage = [UIImage imageNamed:@"uploadFile_image"]; //[self.view addSubview:_curScrollView]; [self.view insertSubview:_curScrollView belowSubview:self.navBarBGView]; _curScrollView.backgroundColor = [UIColor blackColor]; [_curScrollView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); //make.top.equalTo(self.navBarBGView.mas_bottom).offset(0); make.top.mas_equalTo(0); //make.bottom.mas_equalTo(-(60+ AdaptTabHeight)); make.bottom.mas_equalTo(0); }]; KWeakSelf dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self->_curScrollView makeScrollViewScrollToIndex:self->_index]; [weakSelf setTitleLabelTextFunBy:self->_index]; [weakSelf cycleScrollViewDidScrollToIndex:self->_index]; self->_curScrollView.hidden = NO; }); _curScrollView.itemDidScrollOperationBlock = ^(NSInteger currentIndex) { //屏幕旋转 这里回调 而且值差几个 if(currentIndex + 1 == weakSelf.index ||currentIndex -1 == weakSelf.index){ weakSelf.index = currentIndex; } HLog(@"curIndexcurIndex 1111:%ld --%ld",currentIndex,weakSelf.index) [weakSelf setTitleLabelTextFunBy:currentIndex]; [weakSelf cycleScrollViewDidScrollToIndex:currentIndex]; }; _curScrollView.clickItemOperationBlock = ^(NSInteger currentIndex) { self->_isHideMsgType = !self->_isHideMsgType; [weakSelf didClickScreenFun:self->_isHideMsgType]; }; if(_curEditTypeBottomView){ [_curEditTypeBottomView removeFromSuperview]; _curEditTypeBottomView = nil; } _curEditTypeBottomView = [[editTypeBottomView alloc] init]; _curEditTypeBottomView.isBlackType = YES; [self.view addSubview:_curEditTypeBottomView]; //_curEditTypeBottomView.hidden = YES; //_curEditTypeBottomView.backgroundColor = [UIColor greenColor]; if(!_isPortraitType){ _curEditTypeBottomView.hidden = YES; } [_curEditTypeBottomView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.bottom.mas_equalTo(0); make.height.mas_equalTo(60 + AdaptTabHeight); }]; //KWeakSelf #pragma mark 编辑状态的 下载 分享 删除 响应事件 _curEditTypeBottomView.didClickButtonFun = ^(NSInteger tag) { if(tag==1){ //[[iToast makeText:@"点击下载"] show]; [weakSelf gotoDownLoadFileFun]; } else if(tag==2){ [weakSelf gotoShareViewFun]; } else if(tag==3){ //[[iToast makeText:@"点击删除"] show]; [weakSelf showDeleteAlearViewFun]; } }; } - (void)setTitleLabelTextFunBy:(NSInteger)index { if(index >=0 && index < _totalDataArr.count){ NASFilePicDataArrModel *dataModel = _totalDataArr[index]; self.titleLabel.text = dataModel.name; _previewLandscapeTopV.titleLabel.text = dataModel.name; } } #pragma mark 删除图片 - (void)showDeleteAlearViewFun { NSString *titleStr = NSLocalizedString(@"delete_file_title_msg",nil); NSString *tipStr = NSLocalizedString(@"delete_file_tip_msg",nil); KWeakSelf ComontAlretViewController *curAlretVC= [[ComontAlretViewController alloc] initWithTiTle:titleStr msg:tipStr imageStr:nil cancelTitle:NSLocalizedString(@"other_cancel",nil) okTitle:NSLocalizedString(@"other_confirm",nil) isOkBtnHighlight:YES didClickOk:^{ [weakSelf delFileListFun]; } didClickCancel:^{ }]; curAlretVC.modalPresentationStyle = UIModalPresentationCustom; [self presentViewController:curAlretVC animated:YES completion:^{ curAlretVC.view.superview.backgroundColor = [UIColor clearColor]; }]; } #pragma mark 删除文件数据 - (void)delFileListFun { NSMutableDictionary*paraDict = [NSMutableDictionary new]; NSString *deleteFilePath = @""; if(_index >=0 && _index < _totalDataArr.count){ NASFilePicDataArrModel *dataModel = _totalDataArr[_index]; NSArray *pathArr = @[dataModel.path]; deleteFilePath = dataModel.path; //NSArray *pathArr = @[dataModel.path,dataModel.path]; [paraDict setValue:pathArr forKey:@"path"]; } [self showNewIndicatorWithCanBack:YES canTouch:NO]; //NSString*code = [[NSString alloc] initWithFormat:@"delFile?path=%@",paraDict[@"path"]]; //delFile?path=[/storage/emulated/0/Download/IMG_6464.HEIC] KWeakSelf //@"delFile" [[netWorkManager shareInstance] cloudPhonePostCallBackCode:@"delFile" Parameters:paraDict success:^(id _Nonnull responseObject) { [weakSelf removeNewIndicator]; SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil]; if(model && model.status == 0){ [[iToast makeText:NSLocalizedString(@"delete_file_suc_msg",nil)] show]; if(weakSelf.didNeedDeleteFile){ weakSelf.didNeedDeleteFile(deleteFilePath); } [weakSelf didDeleteSucFun]; [weakSelf.navigationController popViewControllerAnimated:YES]; } else{ } } failure:^(NSError * _Nonnull error) { [weakSelf removeNewIndicator]; }]; //数据埋点 [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Image_delete"]; } #pragma mark 删除成功 - (void)didDeleteSucFun { //删除最近文件 if(_index >=0 && _index < _totalDataArr.count){ NASFilePicDataArrModel *dataModel = _totalDataArr[_index]; [[lastFileManager shareManager] deleteFileInfoWithUrl:dataModel.path]; } [_totalDataArr removeAllObjects]; } - (void)gotoDownLoadFileFun { if(_index >=0 && _index < _totalDataArr.count){ NASFilePicDataArrModel *dataModel = _totalDataArr[_index]; couldPhoneFileModel* fileModel = [couldPhoneFileModel new]; fileModel.fileType = dataModel.type; fileModel.path = dataModel.path; fileModel.name = dataModel.name; fileModel.length = dataModel.size; NSMutableArray *arr = [NSMutableArray new]; [arr addObject:fileModel]; //切换到竖屏 [self hx_rotateToInterfaceOrientation:UIInterfaceOrientationPortrait]; uploadFileRecordViewController *vc = [uploadFileRecordViewController new]; [self.navigationController pushViewController:vc animated:YES]; vc.isDownloadingType = YES; [vc gotoDownloadFile:arr]; } } - (void)setCanShareType:(BOOL)canShareType { _canShareType = canShareType; [_curEditTypeBottomView setCanShaewFunBy:canShareType]; } #pragma mark 图片滑动 - (void)cycleScrollViewDidScrollToIndex:(NSInteger)index{ if(index >=0 && index < _totalDataArr.count){ NASFilePicDataArrModel *dataModel = _totalDataArr[index]; lastFileModel *lastFileMod = [lastFileModel new]; lastFileMod.path = dataModel.path; lastFileMod.name = dataModel.name; lastFileMod.time = dataModel.time; lastFileMod.size = dataModel.size; lastFileMod.duration = dataModel.duration; lastFileMod.type = @".jpg"; lastFileMod.lastPreTime = [iTools getNowTimeStamp]; [[lastFileManager shareManager] saveFileInfoWith:lastFileMod with:dataModel.path]; } } #pragma mark 横屏时点击顶部按钮 - (void)didClickButInLandscapeTopFunBy:(NSInteger)tag { if(tag == 1){ [self backBtnPressed]; } else if(tag == 2){ [self showPreviewLandscapeTopMoreViewFun]; } else if(tag == 3){//分享 [self gotoShareViewFun]; } } #pragma mark 删除横屏的 more - (void)deletePreviewLandscapeTopMoreViewFun { [_previewLandscapeTopMoreV removeFromSuperview]; _previewLandscapeTopMoreV = nil; } #pragma mark 点开了横屏的 more - (void)showPreviewLandscapeTopMoreViewFun { [self deletePreviewLandscapeTopMoreViewFun]; _previewLandscapeTopMoreV = [[previewLandscapeTopMoreView alloc] init]; [self.view addSubview:_previewLandscapeTopMoreV]; [_previewLandscapeTopMoreV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.top.mas_equalTo(0); make.bottom.mas_equalTo(0); }]; KWeakSelf _previewLandscapeTopMoreV.didClickButtonFun = ^(NSInteger tag) { if(tag==10){ //[[iToast makeText:@"点击下载"] show]; //切换到竖屏 [weakSelf hx_rotateToInterfaceOrientation:UIInterfaceOrientationPortrait]; [weakSelf screenLandscapeToPortraitFun]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [weakSelf gotoDownLoadFileFun]; }); } else if(tag==11){ //[[iToast makeText:@"点击删除"] show]; [weakSelf showDeleteAlearViewFun]; } }; } #pragma mark 点开了屏幕 - (void)didClickScreenFun:(BOOL)isHideMsgType { _isHideMsgType = isHideMsgType; if(isHideMsgType){//处理隐藏 if(_isPortraitType){ CGRect BottomViewRect = _curEditTypeBottomView.frame; CGRect fixBottomViewRect = CGRectMake(BottomViewRect.origin.x, BottomViewRect.origin.y + BottomViewRect.size.height, BottomViewRect.size.width, BottomViewRect.size.height); CGRect navBarBGViewRect = self.navBarBGView.frame; CGRect fixNavBarBGViewRect = CGRectMake(navBarBGViewRect.origin.x, navBarBGViewRect.origin.y - navBarBGViewRect.size.height, navBarBGViewRect.size.width, navBarBGViewRect.size.height); [UIView animateWithDuration:0.3 animations:^{ self->_curEditTypeBottomView.frame = fixBottomViewRect; self.navBarBGView.frame = fixNavBarBGViewRect; } completion:^(BOOL finished) { self->_curEditTypeBottomView.hidden = YES; self.navBarBGView.hidden = YES; //frame 还原 self->_curEditTypeBottomView.frame = BottomViewRect; self.navBarBGView.frame = navBarBGViewRect; }]; } else{ CGRect TopViewRect = _previewLandscapeTopV.frame; CGRect fixTopViewRect = CGRectMake(TopViewRect.origin.x, TopViewRect.origin.y - TopViewRect.size.height, TopViewRect.size.width, TopViewRect.size.height); [UIView animateWithDuration:0.3 animations:^{ self->_previewLandscapeTopV.frame = fixTopViewRect; } completion:^(BOOL finished) { self->_previewLandscapeTopV.hidden = YES; //frame 还原 self->_previewLandscapeTopV.frame = TopViewRect; }]; } } else{//处理显示 if(_isPortraitType){ CGRect BottomViewRect = _curEditTypeBottomView.frame; CGRect fixBottomViewRect = CGRectMake(BottomViewRect.origin.x, BottomViewRect.origin.y + BottomViewRect.size.height, BottomViewRect.size.width, BottomViewRect.size.height); CGRect navBarBGViewRect = self.navBarBGView.frame; CGRect fixNavBarBGViewRect = CGRectMake(navBarBGViewRect.origin.x, navBarBGViewRect.origin.y - navBarBGViewRect.size.height, navBarBGViewRect.size.width, navBarBGViewRect.size.height); self->_curEditTypeBottomView.frame = fixBottomViewRect; self.navBarBGView.frame = fixNavBarBGViewRect; [UIView animateWithDuration:0.3 animations:^{ //frame 还原 self->_curEditTypeBottomView.frame = BottomViewRect; self.navBarBGView.frame = navBarBGViewRect; } completion:^(BOOL finished) { self->_curEditTypeBottomView.hidden = NO; self.navBarBGView.hidden = NO; }]; } else{ _previewLandscapeTopV.hidden = NO; CGRect topViewRect = _previewLandscapeTopV.frame; CGRect fixTopViewRect = CGRectMake(topViewRect.origin.x, topViewRect.origin.y - topViewRect.size.height, topViewRect.size.width, topViewRect.size.height); self->_previewLandscapeTopV.frame = fixTopViewRect; [UIView animateWithDuration:0.3 animations:^{ //frame 还原 self->_previewLandscapeTopV.frame = topViewRect; } completion:^(BOOL finished) { self->_previewLandscapeTopV.hidden = NO; }]; } } } @end