123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558 |
- //
- // imageDetailsScrollViewController.m
- // 双子星云手机
- //
- // Created by xd h on 2024/5/16.
- //
- #import "imageDetailsScrollViewController.h"
- #import <SDCycleScrollView/SDCycleScrollView.h>
- #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,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;
- }
- - (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];
- }
- - (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);
- }];
-
- //[_curScrollView.mainView reloadData];
- //[_curScrollView adjustWhenControllerViewWillAppera];
-
- // if(_index >= 1){
- // [_curScrollView makeScrollViewScrollToIndex:_index-1];
- // [_curScrollView makeScrollViewScrollToIndex:_index];
- // }
-
- }
- #pragma mark 横屏转竖屏
- - (void)screenLandscapeToPortraitFun{
- _isPortraitType = YES;
- _curEditTypeBottomView.hidden = NO;
- self.navBarBGView.hidden = NO;
-
- _previewLandscapeTopV.hidden = YES;
-
- [self didClickScreenFun:NO];
-
- //[_curScrollView.mainView reloadData];
- //[self deletePreviewLandscapeTopMoreViewFun];
- // if(_index >= 1){
- // [_curScrollView makeScrollViewScrollToIndex:_index-1];
- // [_curScrollView makeScrollViewScrollToIndex:_index];
- // }
- }
- #pragma mark 用户点击分享
- - (void)gotoShareViewFun
- {
- editShareView *editShareV = [[editShareView alloc] init];
-
- NASFilePicDataArrModel *dataModel = _totalDataArr[_index];
- editShareV.didSelectListArr = [NSMutableArray arrayWithArray:@[dataModel]];
- editShareV.shareFileType = @"2";
-
- [self.view addSubview:editShareV];
-
- [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);
- }];
- }
- - (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);
-
- _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) {
- weakSelf.index = currentIndex;
- [weakSelf setTitleLabelTextFunBy:currentIndex];
- [weakSelf cycleScrollViewDidScrollToIndex:currentIndex];
- };
-
- _curScrollView.clickItemOperationBlock = ^(NSInteger currentIndex) {
- self->_isHideMsgType = !self->_isHideMsgType;
- [weakSelf didClickScreenFun:self->_isHideMsgType];
- };
-
- _curEditTypeBottomView = [[editTypeBottomView alloc] init];
- _curEditTypeBottomView.isBlackType = YES;
- [self.view addSubview:_curEditTypeBottomView];
- //_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];
-
- if(_index >=0 && _index < _totalDataArr.count){
- NASFilePicDataArrModel *dataModel = _totalDataArr[_index];
- NSArray *pathArr = @[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.didNeedToRegetDataFun){
- weakSelf.didNeedToRegetDataFun();
- }
-
- [weakSelf.navigationController popViewControllerAnimated:YES];
- }
- else{
-
- }
- } failure:^(NSError * _Nonnull error) {
- [weakSelf removeNewIndicator];
- }];
- }
- - (void)gotoDownLoadFileFun
- {
- if(_index >=0 && _index < _totalDataArr.count){
- NASFilePicDataArrModel *dataModel = _totalDataArr[_index];
-
- couldPhoneFileModel* fileModel = [couldPhoneFileModel new];
- fileModel.fileType = @".jpg";
- fileModel.path = dataModel.path;
- fileModel.name = dataModel.name;
- fileModel.length = dataModel.size;
-
- NSMutableArray *arr = [NSMutableArray new];
- [arr addObject:fileModel];
-
- 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
|