diff --git a/PhotoBrowser/NSBundle+ZLPhotoBrowser.m b/PhotoBrowser/NSBundle+ZLPhotoBrowser.m index 1b05c59e..23485bc2 100644 --- a/PhotoBrowser/NSBundle+ZLPhotoBrowser.m +++ b/PhotoBrowser/NSBundle+ZLPhotoBrowser.m @@ -8,6 +8,7 @@ #import "NSBundle+ZLPhotoBrowser.h" #import "ZLPhotoActionSheet.h" +#import "ZLDefine.h" @implementation NSBundle (ZLPhotoBrowser) diff --git a/PhotoBrowser/ZLCustomCamera.m b/PhotoBrowser/ZLCustomCamera.m index 0b3488c5..275256ba 100644 --- a/PhotoBrowser/ZLCustomCamera.m +++ b/PhotoBrowser/ZLCustomCamera.m @@ -374,7 +374,7 @@ - (void)dealloc [[AVAudioSession sharedInstance] setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self]; -// NSLog(@"%s", __func__); +// NSLog(@"---- %s", __FUNCTION__); } - (void)viewDidLoad { diff --git a/PhotoBrowser/ZLDefine.h b/PhotoBrowser/ZLDefine.h index ce064e1b..1642471a 100644 --- a/PhotoBrowser/ZLDefine.h +++ b/PhotoBrowser/ZLDefine.h @@ -45,13 +45,6 @@ #define kRGB(r, g, b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1] -#define kNavBar_color kRGB(19, 153, 231) -#define kNavBar_tintColor kRGB(255, 255, 255) -#define kBottomViewBgColor kRGB(255, 255, 255) -#define kDoneButton_textColor kRGB(255, 255, 255) -#define kBottomBtnsNormalTitleColor kRGB(80, 180, 234) -#define kBottomBtnsDisableTitleColor kRGB(200, 200, 200) - #define zl_weakify(var) __weak typeof(var) weakSelf = var #define zl_strongify(var) __strong typeof(var) strongSelf = var diff --git a/PhotoBrowser/ZLEditVideoController.m b/PhotoBrowser/ZLEditVideoController.m index 472c5b6d..80dee14e 100644 --- a/PhotoBrowser/ZLEditVideoController.m +++ b/PhotoBrowser/ZLEditVideoController.m @@ -232,6 +232,7 @@ @implementation ZLEditVideoController - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; +// NSLog(@"---- %s", __FUNCTION__); } - (NSMutableArray *)arrImages @@ -349,7 +350,7 @@ - (void)setupUI - (void)creatBottomView { - ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; + ZLPhotoConfiguration *configuration = [(ZLImageNavigationController *)self.navigationController configuration]; //下方视图 _bottomView = [[UIView alloc] init]; _bottomView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:.7]; @@ -364,7 +365,7 @@ - (void)creatBottomView _doneBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_doneBtn setTitle:GetLocalLanguageTextValue(ZLPhotoBrowserDoneText) forState:UIControlStateNormal]; - [_doneBtn setBackgroundColor:nav.bottomBtnsNormalTitleColor]; + [_doneBtn setBackgroundColor:configuration.bottomBtnsNormalTitleColor]; [_doneBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; _doneBtn.titleLabel.font = [UIFont systemFontOfSize:15]; _doneBtn.layer.masksToBounds = YES; @@ -389,8 +390,8 @@ - (void)analysisAssetImages }); }]; - ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; - _interval = nav.maxEditVideoTime/10.0; + ZLPhotoConfiguration *configuration = [(ZLImageNavigationController *)self.navigationController configuration]; + _interval = configuration.maxEditVideoTime/10.0; [ZLPhotoManager analysisEverySecondsImageForAsset:self.model.asset interval:_interval size:CGSizeMake(kItemWidth*5, kItemHeight*5) complete:^(AVAsset *avAsset, NSArray *images) { [hud hide]; @@ -408,8 +409,10 @@ - (void)cancelBtn_click [self stopTimer]; ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; - if (nav.editAfterSelectThumbnailImage && - nav.maxSelectCount == 1) { + ZLPhotoConfiguration *configuration = nav.configuration; + + if (configuration.editAfterSelectThumbnailImage && + configuration.maxSelectCount == 1) { [nav.arrSelectedModels removeAllObjects]; } diff --git a/PhotoBrowser/ZLEditViewController.m b/PhotoBrowser/ZLEditViewController.m index 67e845c0..6c16bf00 100644 --- a/PhotoBrowser/ZLEditViewController.m +++ b/PhotoBrowser/ZLEditViewController.m @@ -262,6 +262,11 @@ @interface ZLEditViewController () @implementation ZLEditViewController +- (void)dealloc +{ +// NSLog(@"---- %s", __FUNCTION__); +} + - (void)viewDidLoad { [super viewDidLoad]; @@ -328,10 +333,10 @@ - (void)viewDidLayoutSubviews //当裁剪比例只有 custom 或者 1:1 的时候隐藏比例视图 - (BOOL)shouldHideClipRatioView { - ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; - if (nav.clipRatios.count <= 1) { - NSInteger value1 = [nav.clipRatios.firstObject[ClippingRatioValue1] integerValue]; - NSInteger value2 = [nav.clipRatios.firstObject[ClippingRatioValue2] integerValue]; + ZLPhotoConfiguration *configuration = [(ZLImageNavigationController *)self.navigationController configuration]; + if (configuration.clipRatios.count <= 1) { + NSInteger value1 = [configuration.clipRatios.firstObject[ClippingRatioValue1] integerValue]; + NSInteger value2 = [configuration.clipRatios.firstObject[ClippingRatioValue2] integerValue]; if ((value1==0 && value2==0) || (value1==1 && value2==1)) { return YES; } @@ -369,7 +374,7 @@ - (void)initUI - (void)creatBottomView { - ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; + ZLPhotoConfiguration *configuration = [(ZLImageNavigationController *)self.navigationController configuration]; //下方视图 _bottomView = [[UIView alloc] init]; _bottomView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:.7]; @@ -391,7 +396,7 @@ - (void)creatBottomView _doneBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_doneBtn setTitle:GetLocalLanguageTextValue(ZLPhotoBrowserDoneText) forState:UIControlStateNormal]; - [_doneBtn setBackgroundColor:nav.bottomBtnsNormalTitleColor]; + [_doneBtn setBackgroundColor:configuration.bottomBtnsNormalTitleColor]; [_doneBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; _doneBtn.titleLabel.font = [UIFont systemFontOfSize:15]; _doneBtn.layer.masksToBounds = YES; @@ -471,11 +476,10 @@ - (void)setCropMenu CGFloat W = 70; CGFloat x = 0; - ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; + ZLPhotoConfiguration *configuration = [(ZLImageNavigationController *)self.navigationController configuration]; //如需要其他比例,请按照格式自行设置 - NSArray *ratios = nav.clipRatios; - for(NSDictionary *info in ratios){ + for(NSDictionary *info in configuration.clipRatios){ CGFloat val1 = [info[@"value1"] floatValue]; CGFloat val2 = [info[@"value2"] floatValue]; @@ -771,8 +775,10 @@ - (void)panGridView:(UIPanGestureRecognizer*)sender - (void)cancelBtn_click { ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; - if (nav.editAfterSelectThumbnailImage && - nav.maxSelectCount == 1) { + ZLPhotoConfiguration *configuration = nav.configuration; + + if (configuration.editAfterSelectThumbnailImage && + configuration.maxSelectCount == 1) { [nav.arrSelectedModels removeAllObjects]; } UIViewController *vc = [self.navigationController popViewControllerAnimated:NO]; diff --git a/PhotoBrowser/ZLPhotoActionSheet.h b/PhotoBrowser/ZLPhotoActionSheet.h index d5e546fb..f60c6dc7 100644 --- a/PhotoBrowser/ZLPhotoActionSheet.h +++ b/PhotoBrowser/ZLPhotoActionSheet.h @@ -8,213 +8,25 @@ //pods version 2.5.1.1 - 2017.11.15 update #import -#import "ZLDefine.h" NS_ASSUME_NONNULL_BEGIN @class ZLPhotoModel; @class PHAsset; -@class AVPlayerItem; +@class ZLPhotoConfiguration; @interface ZLPhotoActionSheet : UIView @property (nonatomic, weak) UIViewController *sender; -/** - 最大选择数 默认10张 - */ -@property (nonatomic, assign) NSInteger maxSelectCount; - -/** - 预览图最大显示数 默认20张 - */ -@property (nonatomic, assign) NSInteger maxPreviewCount; - -/** - cell的圆角弧度 默认为0 - */ -@property (nonatomic, assign) CGFloat cellCornerRadio; - -/** - 是否允许混合选择,即可以同时选择image(image/gif/livephoto)、video类型 - */ -@property (nonatomic, assign) BOOL allowMixSelect; - -/** - 是否允许选择照片 默认YES - */ -@property (nonatomic, assign) BOOL allowSelectImage; - -/** - 是否允许选择视频 默认YES - */ -@property (nonatomic, assign) BOOL allowSelectVideo; - -/** - 是否允许选择Gif,只是控制是否选择,并不控制是否显示,如果为NO,则不显示gif标识 默认YES - */ -@property (nonatomic, assign) BOOL allowSelectGif; - -/** - * 是否允许选择Live Photo,只是控制是否选择,并不控制是否显示,如果为NO,则不显示Live Photo标识 默认NO - * @warning ios9 以上系统支持 - */ -@property (nonatomic, assign) BOOL allowSelectLivePhoto; - -/** - 是否允许相册内部拍照 默认YES - */ -@property (nonatomic, assign) BOOL allowTakePhotoInLibrary; - -/** - 是否允许Force Touch功能 默认YES - */ -@property (nonatomic, assign) BOOL allowForceTouch; - -/** - 是否允许编辑图片,选择一张时候才允许编辑,默认YES - */ -@property (nonatomic, assign) BOOL allowEditImage; - -/** - 是否允许编辑视频,选择一张时候才允许编辑,默认NO - */ -@property (nonatomic, assign) BOOL allowEditVideo; - -/** - 是否允许选择原图,默认YES - */ -@property (nonatomic, assign) BOOL allowSelectOriginal; - -/** - 编辑视频时最大裁剪时间,单位:秒,默认10s 且最低10s - - @discussion 当该参数为10s时,所选视频时长必须大于等于10s才允许进行编辑 - */ -@property (nonatomic, assign) NSInteger maxEditVideoTime; +/**相册框架配置*/ +@property (nonatomic, strong) ZLPhotoConfiguration *configuration; /** - 允许选择视频的最大时长,单位:秒, 默认 120s - */ -@property (nonatomic, assign) NSInteger maxVideoDuration; - -/** - 是否允许滑动选择 默认 YES - */ -@property (nonatomic, assign) BOOL allowSlideSelect; - -/** - 预览界面是否允许拖拽选择 默认 NO - */ -@property (nonatomic, assign) BOOL allowDragSelect; - -/** - 根据需要设置自身需要的裁剪比例 - - @discussion e.g.:1:1,请使用ZLDefine中所提供方法 GetClipRatio(NSInteger value1, NSInteger value2),该数组可不设置,有默认比例,为(Custom, 1:1, 4:3, 3:2, 16:9) - */ -@property (nonatomic, strong) NSArray *clipRatios; - -/** - 在小图界面选择 图片/视频 后直接进入编辑界面,默认NO - - @discussion 编辑图片 仅在allowEditImage为YES 且 maxSelectCount为1 的情况下,置为YES有效,编辑视频则在 allowEditVideo为YES 且 maxSelectCount为1情况下,置为YES有效 - */ -@property (nonatomic, assign) BOOL editAfterSelectThumbnailImage; - -/** - 是否在相册内部拍照按钮上面实时显示相机俘获的影像 默认 YES - */ -@property (nonatomic, assign) BOOL showCaptureImageOnTakePhotoBtn; - -/** - 是否升序排列,预览界面不受该参数影响,默认升序 YES - */ -@property (nonatomic, assign) BOOL sortAscending; - -/** - 控制单选模式下,是否显示选择按钮,默认 NO,多选模式不受控制 - */ -@property (nonatomic, assign) BOOL showSelectBtn; - -/** - 已选择的asset对象数组 + 已选择的asset对象数组,用于标记已选择的图片 */ @property (nonatomic, strong, nullable) NSMutableArray *arrSelectedAssets; -/** - 导航条颜色,默认 rgb(19, 153, 231) - */ -@property (nonatomic, strong) UIColor *navBarColor; - -/** - 导航标题颜色,默认 rgb(255, 255, 255) - */ -@property (nonatomic, strong) UIColor *navTitleColor; - -/** - 底部工具条底色,默认 rgb(255, 255, 255) - */ -@property (nonatomic, strong) UIColor *bottomViewBgColor; - -/** - 底部工具栏按钮 可交互 状态标题颜色,底部 toolbar 按钮可交互状态title颜色均使用这个,确定按钮 可交互 的背景色为这个,默认rgb(80, 180, 234) - */ -@property (nonatomic, strong) UIColor *bottomBtnsNormalTitleColor; - -/** - 底部工具栏按钮 不可交互 状态标题颜色,底部 toolbar 按钮不可交互状态颜色均使用这个,确定按钮 不可交互 的背景色为这个,默认rgb(200, 200, 200) - */ -@property (nonatomic, strong) UIColor *bottomBtnsDisableBgColor; - -/** - 是否在已选择的图片上方覆盖一层已选中遮罩层,默认 NO - */ -@property (nonatomic, assign) BOOL showSelectedMask; - -/** - 遮罩层颜色,内部会默认调整颜色的透明度为0.2, 默认 blackColor - */ -@property (nonatomic, strong) UIColor *selectedMaskColor; - -/** - 支持开发者自定义图片,但是所自定义图片资源名称必须与被替换的bundle中的图片名称一致 - @example: 开发者需要替换选中与未选中的图片资源,则需要传入的数组为 @[@"btn_selected", @"btn_unselected"],则框架内会使用开发者项目中的图片资源,而其他图片则用框架bundle中的资源 - */ -@property (nonatomic, strong) NSArray *customImageNames; - -/** - 回调时候是否允许框架解析图片,默认YES - - 如果选择了大量图片,框架一下解析大量图片会耗费一些内存,开发者此时可置为NO,拿到assets数组后自行解析,该值为NO时,回调的图片数组为nil - */ -@property (nonatomic, assign) BOOL shouldAnialysisAsset; - -/** - 框架语言,默认 ZLLanguageSystem (跟随系统语言) - 仅切换框架内定义的语言,由于相册名字根据系统语言进行获取,所以相册列表界面为当前系统语言 - */ -@property (nonatomic, assign) ZLLanguageType languageType; - -/** - 使用系统相机,默认NO(系统相机则只能进行拍照) - */ -@property (nonatomic, assign) BOOL useSystemCamera; - -/** - 是否允许录制视频(当useSystemCamera为YES时无效),默认YES - */ -@property (nonatomic, assign) BOOL allowRecordVideo; - -/** - 最大录制时长,默认 10s,最小为 1s - */ -@property (nonatomic, assign) NSInteger maxRecordDuration; - -/** - 视频清晰度,默认ZLCaptureSessionPreset1280x720 - */ -@property (nonatomic, assign) ZLCaptureSessionPreset sessionPreset; /** 选择照片回调,回调解析好的图片、对应的asset对象、是否原图 @@ -256,7 +68,6 @@ NS_ASSUME_NONNULL_BEGIN - (void)showPhotoLibraryWithSender:(UIViewController *)sender; - /** 提供 预览用户已选择的照片,并可以取消已选择的照片 diff --git a/PhotoBrowser/ZLPhotoActionSheet.m b/PhotoBrowser/ZLPhotoActionSheet.m index 5f079971..4262258f 100644 --- a/PhotoBrowser/ZLPhotoActionSheet.m +++ b/PhotoBrowser/ZLPhotoActionSheet.m @@ -7,9 +7,7 @@ // #import "ZLPhotoActionSheet.h" -#import #import "ZLCollectionCell.h" -#import "ZLPhotoModel.h" #import "ZLPhotoManager.h" #import "ZLPhotoBrowser.h" #import "ZLShowBigImgViewController.h" @@ -18,10 +16,11 @@ #import "ToastUtils.h" #import "ZLEditViewController.h" #import "ZLEditVideoController.h" -#import "NSBundle+ZLPhotoBrowser.h" #import "ZLCustomCamera.h" +#import "ZLDefine.h" +#import "ZLPhotoConfiguration.h" -#define kBaseViewHeight (self.maxPreviewCount ? 300 : 142) +#define kBaseViewHeight (self.configuration.maxPreviewCount ? 300 : 142) double const ScalePhotoWidth = 1000; @@ -108,38 +107,6 @@ - (void)setArrSelectedAssets:(NSMutableArray *)arrSelectedAssets } } -- (void)setAllowSelectLivePhoto:(BOOL)allowSelectLivePhoto -{ - _allowSelectLivePhoto = allowSelectLivePhoto; - if ([UIDevice currentDevice].systemVersion.floatValue < 9.0) { - _allowSelectLivePhoto = NO; - } -} - -- (void)setMaxEditVideoTime:(NSInteger)maxEditVideoTime -{ - _maxEditVideoTime = MAX(maxEditVideoTime, 10); -} - -- (void)setCustomImageNames:(NSArray *)customImageNames -{ - _customImageNames = customImageNames; - [[NSUserDefaults standardUserDefaults] setValue:customImageNames forKey:ZLCustomImageNames]; - [[NSUserDefaults standardUserDefaults] synchronize]; -} - -- (void)setLanguageType:(ZLLanguageType)languageType -{ - [[NSUserDefaults standardUserDefaults] setValue:@(languageType) forKey:ZLLanguageTypeKey]; - [[NSUserDefaults standardUserDefaults] synchronize]; - [NSBundle resetLanguage]; -} - -- (void)setMaxRecordDuration:(NSInteger)maxRecordDuration -{ - _maxRecordDuration = MAX(maxRecordDuration, 1); -} - - (instancetype)init { self = [[kZLPhotoBrowserBundle loadNibNamed:@"ZLPhotoActionSheet" owner:self options:nil] lastObject]; @@ -152,37 +119,6 @@ - (instancetype)init self.collectionView.collectionViewLayout = layout; self.collectionView.backgroundColor = [UIColor whiteColor]; [self.collectionView registerClass:NSClassFromString(@"ZLCollectionCell") forCellWithReuseIdentifier:@"ZLCollectionCell"]; - - self.maxSelectCount = 10; - self.maxPreviewCount = 20; - self.maxVideoDuration = 120; - self.cellCornerRadio = .0; - self.allowSelectImage = YES; - self.allowSelectVideo = YES; - self.allowSelectGif = YES; - self.allowSelectLivePhoto = NO; - self.allowTakePhotoInLibrary = YES; - self.allowForceTouch = YES; - self.allowEditImage = YES; - self.allowEditVideo = NO; - self.allowSelectOriginal = YES; - self.maxEditVideoTime = 10; - self.allowSlideSelect = YES; - self.allowDragSelect = NO; - self.editAfterSelectThumbnailImage = NO; - self.allowMixSelect = YES; - self.showCaptureImageOnTakePhotoBtn = YES; - self.sortAscending = YES; - self.showSelectBtn = NO; - self.showSelectedMask = NO; - self.shouldAnialysisAsset = YES; - self.selectedMaskColor = [UIColor blackColor]; - self.bottomBtnsNormalTitleColor = kBottomBtnsNormalTitleColor; - self.languageType = ZLLanguageSystem; - self.useSystemCamera = NO; - self.allowRecordVideo = YES; - self.sessionPreset = ZLCaptureSessionPreset1280x720; - self.maxRecordDuration = 10; if (![ZLPhotoManager havePhotoLibraryAuthority]) { //注册实施监听相册变化 [[PHPhotoLibrary sharedPhotoLibrary] registerChangeObserver:self]; @@ -238,23 +174,24 @@ - (void)showPhotoLibrary - (void)showPreview:(BOOL)preview animate:(BOOL)animate { - if (!self.allowSelectImage && self.arrSelectedModels.count) { + NSAssert(self.configuration != nil, @"相册框架配置 configuration 对象不能为空"); + NSAssert(self.sender != nil, @"sender 对象不能为空"); + + if (!self.configuration.allowSelectImage && self.arrSelectedModels.count) { [self.arrSelectedAssets removeAllObjects]; [self.arrSelectedModels removeAllObjects]; } - if (self.maxSelectCount > 1) { - self.showSelectBtn = YES; - } + self.animate = animate; self.preview = preview; self.previousStatusBarStyle = [UIApplication sharedApplication].statusBarStyle; self.previousStatusBarIsHidden = [UIApplication sharedApplication].isStatusBarHidden; - [ZLPhotoManager setSortAscending:self.sortAscending]; + [ZLPhotoManager setSortAscending:self.configuration.sortAscending]; - if (!self.maxPreviewCount) { + if (!self.configuration.maxPreviewCount) { self.verColHeight.constant = .0; - } else if (self.maxSelectCount && self.allowDragSelect) { + } else if (self.configuration.allowDragSelect) { UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)]; [self.baseView addGestureRecognizer:pan]; } @@ -292,15 +229,21 @@ - (void)previewSelectedPhotos:(NSArray *)photos assets:(NSArray *photos, NSArray *assets) { + svc.previewSelectedImageBlock = ^(NSArray *arrP, NSArray *arrA) { zl_strongify(weakSelf); strongSelf.arrSelectedAssets = assets.mutableCopy; __strong typeof(weakNav) strongNav = weakNav; if (strongSelf.selectImageBlock) { - strongSelf.selectImageBlock(photos, assets, NO); + strongSelf.selectImageBlock(arrP, arrA, NO); } + [strongSelf hide]; [strongNav dismissViewControllerAnimated:YES completion:nil]; - }]; + }; + + svc.cancelPreviewBlock = ^{ + zl_strongify(weakSelf); + [strongSelf hide]; + }; } - (void)previewPhotos:(NSArray *)photos index:(NSInteger)index hideToolBar:(BOOL)hideToolBar complete:(nonnull void (^)(NSArray * _Nonnull))complete @@ -319,19 +262,27 @@ - (void)previewPhotos:(NSArray *)photos index:(NSInteger)index hideToolBar:(BOOL } ZLShowBigImgViewController *svc = [self pushBigImageToPreview:photos index:index]; svc.hideToolBar = hideToolBar; + + zl_weakify(self); __weak typeof(svc.navigationController) weakNav = svc.navigationController; [svc setPreviewNetImageBlock:^(NSArray *photos) { + zl_strongify(weakSelf); __strong typeof(weakNav) strongNav = weakNav; if (complete) complete(photos); + [strongSelf hide]; [strongNav dismissViewControllerAnimated:YES completion:nil]; }]; + svc.cancelPreviewBlock = ^{ + zl_strongify(weakSelf); + [strongSelf hide]; + }; } - (void)loadPhotoFromAlbum { [self.arrDataSources removeAllObjects]; - [self.arrDataSources addObjectsFromArray:[ZLPhotoManager getAllAssetInPhotoAlbumWithAscending:NO limitCount:self.maxPreviewCount allowSelectVideo:self.allowSelectVideo allowSelectImage:self.allowSelectImage allowSelectGif:self.allowSelectGif allowSelectLivePhoto:self.allowSelectLivePhoto]]; + [self.arrDataSources addObjectsFromArray:[ZLPhotoManager getAllAssetInPhotoAlbumWithAscending:NO limitCount:self.configuration.maxPreviewCount allowSelectVideo:self.configuration.allowSelectVideo allowSelectImage:self.configuration.allowSelectImage allowSelectGif:self.configuration.allowSelectGif allowSelectLivePhoto:self.configuration.allowSelectLivePhoto]]; [ZLPhotoManager markSelcectModelInArr:self.arrDataSources selArr:self.arrSelectedModels]; [self.collectionView reloadData]; } @@ -403,9 +354,6 @@ - (void)hide if (self.senderTabBarIsShow) { self.sender.tabBarController.tabBar.hidden = NO; } - - [[NSUserDefaults standardUserDefaults] removeObjectForKey:ZLCustomImageNames]; - [[NSUserDefaults standardUserDefaults] synchronize]; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event @@ -498,7 +446,7 @@ - (IBAction)btnCamera_Click:(id)sender [self hide]; return; } - if (self.useSystemCamera) { + if (self.configuration.useSystemCamera) { //系统相机拍照 if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]){ @@ -517,10 +465,10 @@ - (IBAction)btnCamera_Click:(id)sender return; } ZLCustomCamera *camera = [[ZLCustomCamera alloc] init]; - camera.allowRecordVideo = self.allowRecordVideo; - camera.sessionPreset = self.sessionPreset; - camera.circleProgressColor = self.bottomBtnsNormalTitleColor; - camera.maxRecordDuration = self.maxRecordDuration; + camera.allowRecordVideo = self.configuration.allowRecordVideo; + camera.sessionPreset = self.configuration.sessionPreset; + camera.circleProgressColor = self.configuration.bottomBtnsNormalTitleColor; + camera.maxRecordDuration = self.configuration.maxRecordDuration; zl_weakify(self); camera.doneBlock = ^(UIImage *image, NSURL *videoUrl) { zl_strongify(weakSelf); @@ -553,7 +501,7 @@ - (void)changeCancelBtnTitle { if (self.arrSelectedModels.count > 0) { [self.btnCancel setTitle:[NSString stringWithFormat:@"%@(%ld)", GetLocalLanguageTextValue(ZLPhotoBrowserDoneText), self.arrSelectedModels.count] forState:UIControlStateNormal]; - [self.btnCancel setTitleColor:self.bottomBtnsNormalTitleColor forState:UIControlStateNormal]; + [self.btnCancel setTitleColor:self.configuration.bottomBtnsNormalTitleColor forState:UIControlStateNormal]; } else { [self.btnCancel setTitle:GetLocalLanguageTextValue(ZLPhotoBrowserCancelText) forState:UIControlStateNormal]; [self.btnCancel setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; @@ -566,7 +514,7 @@ - (void)requestSelPhotos:(UIViewController *)vc data:(NSArray *) ZLProgressHUD *hud = [[ZLProgressHUD alloc] init]; [hud show]; - if (!self.shouldAnialysisAsset) { + if (!self.configuration.shouldAnialysisAsset) { NSMutableArray *assets = [NSMutableArray arrayWithCapacity:data.count]; for (ZLPhotoModel *m in data) { [assets addObject:m.asset]; @@ -593,7 +541,7 @@ - (void)requestSelPhotos:(UIViewController *)vc data:(NSArray *) zl_weakify(self); for (int i = 0; i < data.count; i++) { ZLPhotoModel *model = data[i]; - [ZLPhotoManager requestSelectedImageForAsset:model isOriginal:self.isSelectOriginalPhoto allowSelectGif:self.allowSelectGif completion:^(UIImage *image, NSDictionary *info) { + [ZLPhotoManager requestSelectedImageForAsset:model isOriginal:self.isSelectOriginalPhoto allowSelectGif:self.configuration.allowSelectGif completion:^(UIImage *image, NSDictionary *info) { if ([[info objectForKey:PHImageResultIsDegradedKey] boolValue]) return; zl_strongify(weakSelf); @@ -649,13 +597,13 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell __strong typeof(weakCell) strongCell = weakCell; if (!selected) { //选中 - if (strongSelf.arrSelectedModels.count >= strongSelf.maxSelectCount) { - ShowToastLong(GetLocalLanguageTextValue(ZLPhotoBrowserMaxSelectCountText), strongSelf.maxSelectCount); + if (strongSelf.arrSelectedModels.count >= strongSelf.configuration.maxSelectCount) { + ShowToastLong(GetLocalLanguageTextValue(ZLPhotoBrowserMaxSelectCountText), strongSelf.configuration.maxSelectCount); return; } if (strongSelf.arrSelectedModels.count > 0) { ZLPhotoModel *sm = strongSelf.arrSelectedModels.firstObject; - if (!self.allowMixSelect && + if (!strongSelf.configuration.allowMixSelect && ((model.type < ZLAssetMediaTypeVideo && sm.type == ZLAssetMediaTypeVideo) || (model.type == ZLAssetMediaTypeVideo && sm.type < ZLAssetMediaTypeVideo))) { ShowToastLong(@"%@", GetLocalLanguageTextValue(ZLPhotoBrowserCannotSelectVideo)); return; @@ -665,8 +613,8 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell ShowToastLong(@"%@", GetLocalLanguageTextValue(ZLPhotoBrowseriCloudPhotoText)); return; } - if (model.type == ZLAssetMediaTypeVideo && GetDuration(model.duration) > strongSelf.maxVideoDuration) { - ShowToastLong(GetLocalLanguageTextValue(ZLPhotoBrowserMaxVideoDurationText), strongSelf.maxVideoDuration); + if (model.type == ZLAssetMediaTypeVideo && GetDuration(model.duration) > strongSelf.configuration.maxVideoDuration) { + ShowToastLong(GetLocalLanguageTextValue(ZLPhotoBrowserMaxVideoDurationText), strongSelf.configuration.maxVideoDuration); return; } @@ -686,18 +634,18 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell } } - if (strongSelf.showSelectedMask) { + if (strongSelf.configuration.showSelectedMask) { strongCell.topView.hidden = !model.isSelected; } [strongSelf changeCancelBtnTitle]; }; - cell.allSelectGif = self.allowSelectGif; - cell.allSelectLivePhoto = self.allowSelectLivePhoto; - cell.showSelectBtn = self.showSelectBtn; - cell.cornerRadio = self.cellCornerRadio; - cell.showMask = self.showSelectedMask; - cell.maskColor = self.selectedMaskColor; + cell.allSelectGif = self.configuration.allowSelectGif; + cell.allSelectLivePhoto = self.configuration.allowSelectLivePhoto; + cell.showSelectBtn = self.configuration.showSelectBtn; + cell.cornerRadio = self.configuration.cellCornerRadio; + cell.showMask = self.configuration.showSelectedMask; + cell.maskColor = self.configuration.selectedMaskColor; cell.model = model; return cell; @@ -718,17 +666,17 @@ - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPa if (self.arrSelectedModels.count > 0) { ZLPhotoModel *sm = self.arrSelectedModels.firstObject; - if (!self.allowMixSelect && + if (!self.configuration.allowMixSelect && ((model.type < ZLAssetMediaTypeVideo && sm.type == ZLAssetMediaTypeVideo) || (model.type == ZLAssetMediaTypeVideo && sm.type < ZLAssetMediaTypeVideo))) { ShowToastLong(@"%@", GetLocalLanguageTextValue(ZLPhotoBrowserCannotSelectVideo)); return; } } - BOOL allowSelImage = !(model.type==ZLAssetMediaTypeVideo)?YES:self.allowMixSelect; - BOOL allowSelVideo = model.type==ZLAssetMediaTypeVideo?YES:self.allowMixSelect; + BOOL allowSelImage = !(model.type==ZLAssetMediaTypeVideo)?YES:self.configuration.allowMixSelect; + BOOL allowSelVideo = model.type==ZLAssetMediaTypeVideo?YES:self.configuration.allowMixSelect; - NSArray *arr = [ZLPhotoManager getAllAssetInPhotoAlbumWithAscending:self.sortAscending limitCount:NSIntegerMax allowSelectVideo:allowSelVideo allowSelectImage:allowSelImage allowSelectGif:self.allowSelectGif allowSelectLivePhoto:self.allowSelectLivePhoto]; + NSArray *arr = [ZLPhotoManager getAllAssetInPhotoAlbumWithAscending:self.configuration.sortAscending limitCount:NSIntegerMax allowSelectVideo:allowSelVideo allowSelectImage:allowSelImage allowSelectGif:self.configuration.allowSelectGif allowSelectLivePhoto:self.configuration.allowSelectLivePhoto]; NSMutableArray *selIdentifiers = [NSMutableArray array]; for (ZLPhotoModel *m in self.arrSelectedModels) { @@ -755,9 +703,9 @@ - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPa - (BOOL)shouldDirectEdit:(ZLPhotoModel *)model { //当前点击图片可编辑 - BOOL editImage = self.editAfterSelectThumbnailImage && self.allowEditImage && self.maxSelectCount == 1 && model.type < ZLAssetMediaTypeVideo; + BOOL editImage = self.configuration.editAfterSelectThumbnailImage && self.configuration.allowEditImage && self.configuration.maxSelectCount == 1 && model.type < ZLAssetMediaTypeVideo; //当前点击视频可编辑 - BOOL editVideo = self.editAfterSelectThumbnailImage && self.allowEditVideo && model.type == ZLAssetMediaTypeVideo && self.maxSelectCount == 1 && round(model.asset.duration) >= self.maxEditVideoTime; + BOOL editVideo = self.configuration.editAfterSelectThumbnailImage && self.configuration.allowEditVideo && model.type == ZLAssetMediaTypeVideo && self.configuration.maxSelectCount == 1 && round(model.asset.duration) >= self.configuration.maxEditVideoTime; //当前未选择图片 或已经选择了一张并且点击的是已选择的图片 BOOL flag = self.arrSelectedModels.count == 0 || (self.arrSelectedModels.count == 1 && [self.arrSelectedModels.firstObject.asset.localIdentifier isEqualToString:model.asset.localIdentifier]); @@ -767,7 +715,7 @@ - (BOOL)shouldDirectEdit:(ZLPhotoModel *)model [self pushEditVideoVCWithModel:model]; } - return self.editAfterSelectThumbnailImage && self.maxSelectCount == 1 && (self.allowEditImage || self.allowEditVideo); + return self.configuration.editAfterSelectThumbnailImage && self.configuration.maxSelectCount == 1 && (self.configuration.allowEditImage || self.configuration.allowEditVideo); } #pragma mark - 显示无权限视图 @@ -805,39 +753,9 @@ - (ZLImageNavigationController *)getImageNavWithRootVC:(UIViewController *)rootV [strongSelf hide]; }]; - nav.previousStatusBarStyle = self.previousStatusBarStyle; - nav.maxSelectCount = self.maxSelectCount; - nav.maxVideoDuration = self.maxVideoDuration; - nav.cellCornerRadio = self.cellCornerRadio; - nav.allowSelectVideo = self.allowSelectVideo; - nav.allowSelectImage = self.allowSelectImage; - nav.allowSelectGif = self.allowSelectGif; - nav.allowSelectLivePhoto = self.allowSelectLivePhoto; - nav.allowTakePhotoInLibrary = self.allowTakePhotoInLibrary; - nav.allowForceTouch = self.allowForceTouch; - nav.allowEditImage = self.allowEditImage; - nav.allowEditVideo = self.allowEditVideo; - nav.allowSelectOriginal = self.allowSelectOriginal; - nav.maxEditVideoTime = self.maxEditVideoTime; - nav.allowSlideSelect = self.allowSlideSelect; - nav.editAfterSelectThumbnailImage = self.editAfterSelectThumbnailImage; - nav.clipRatios = self.clipRatios; - nav.allowMixSelect = self.allowMixSelect; - nav.showCaptureImageOnTakePhotoBtn = self.showCaptureImageOnTakePhotoBtn; - nav.sortAscending = self.sortAscending; - nav.showSelectBtn = self.showSelectBtn; nav.isSelectOriginalPhoto = self.isSelectOriginalPhoto; - nav.navBarColor = self.navBarColor; - nav.navTitleColor = self.navTitleColor; - nav.bottomBtnsNormalTitleColor = self.bottomBtnsNormalTitleColor; - nav.bottomBtnsDisableBgColor = self.bottomBtnsDisableBgColor; - nav.bottomViewBgColor = self.bottomViewBgColor; - nav.showSelectedMask = self.showSelectedMask; - nav.selectedMaskColor = self.selectedMaskColor; - nav.useSystemCamera = self.useSystemCamera; - nav.allowRecordVideo = self.allowRecordVideo; - nav.sessionPreset = self.sessionPreset; - nav.maxRecordDuration = self.maxRecordDuration; + nav.previousStatusBarStyle = self.previousStatusBarStyle; + nav.configuration = self.configuration; [nav.arrSelectedModels removeAllObjects]; [nav.arrSelectedModels addObjectsFromArray:self.arrSelectedModels]; @@ -880,7 +798,7 @@ - (ZLShowBigImgViewController *)pushBigImageToPreview:(NSArray *)photos index:(N { ZLShowBigImgViewController *svc = [[ZLShowBigImgViewController alloc] init]; ZLImageNavigationController *nav = [self getImageNavWithRootVC:svc]; - nav.showSelectBtn = YES; + nav.configuration.showSelectBtn = YES; svc.selectIndex = index; svc.arrSelPhotos = [NSMutableArray arrayWithArray:photos]; svc.models = self.arrSelectedModels; @@ -958,10 +876,10 @@ - (void)handleDataArray:(ZLPhotoModel *)model { [self.arrDataSources insertObject:model atIndex:0]; [self.arrDataSources removeLastObject]; - if (self.maxSelectCount > 1 && self.arrSelectedModels.count < self.maxSelectCount) { + if (self.configuration.maxSelectCount > 1 && self.arrSelectedModels.count < self.configuration.maxSelectCount) { model.selected = YES; [self.arrSelectedModels addObject:model]; - } else if (self.maxSelectCount == 1 && !self.arrSelectedModels.count) { + } else if (self.configuration.maxSelectCount == 1 && !self.arrSelectedModels.count) { if (![self shouldDirectEdit:model]) { model.selected = YES; [self.arrSelectedModels addObject:model]; diff --git a/PhotoBrowser/ZLPhotoBrowser.h b/PhotoBrowser/ZLPhotoBrowser.h index 9fc1c2ca..c9cfa00c 100644 --- a/PhotoBrowser/ZLPhotoBrowser.h +++ b/PhotoBrowser/ZLPhotoBrowser.h @@ -8,119 +8,14 @@ #import #import "ZLDefine.h" +#import "ZLPhotoConfiguration.h" @class ZLPhotoModel; -@class PHAsset; -@class AVPlayerItem; @interface ZLImageNavigationController : UINavigationController @property (nonatomic, assign) UIStatusBarStyle previousStatusBarStyle; -/** - 最大选择数 默认10张 - */ -@property (nonatomic, assign) NSInteger maxSelectCount; - -/** - cell的圆角弧度 默认为0 - */ -@property (nonatomic, assign) CGFloat cellCornerRadio; - -/** - 是否允许混合选择,即可以同时选择image(image/gif/livephoto)、video类型 - */ -@property (nonatomic, assign) BOOL allowMixSelect; - -/** - 是否允许选择照片 默认YES - */ -@property (nonatomic, assign) BOOL allowSelectImage; - -/** - 是否允许选择视频 默认YES - */ -@property (nonatomic, assign) BOOL allowSelectVideo; - -/** - 是否允许选择Gif 默认YES - */ -@property (nonatomic, assign) BOOL allowSelectGif; - -/** - 是否允许选择Live Photo,默认NO - */ -@property (nonatomic, assign) BOOL allowSelectLivePhoto; - -/** - 是否允许相册内部拍照 默认YES - */ -@property (nonatomic, assign) BOOL allowTakePhotoInLibrary; - -/** - 是否Force Touch 功能 默认YES - */ -@property (nonatomic, assign) BOOL allowForceTouch; - -/** - 是否允许编辑图片,选择一张时候才允许编辑,默认YES - */ -@property (nonatomic, assign) BOOL allowEditImage; - -/** - 是否允许编辑视频,选择一张时候才允许编辑,默认NO,编辑视频 - */ -@property (nonatomic, assign) BOOL allowEditVideo; - -/** - 是否允许选择原图,默认YES - */ -@property (nonatomic, assign) BOOL allowSelectOriginal; - -/** - 编辑视频时最大裁剪时间,单位:秒,默认10s - - @discussion 当该参数为10s时,所选视频时长必须大于等于10s才允许进行编辑 - */ -@property (nonatomic, assign) NSInteger maxEditVideoTime; - -/** - 允许选择视频的最大时长,单位:秒, 默认 120s - */ -@property (nonatomic, assign) NSInteger maxVideoDuration; - -/** - 是否允许滑动选择 默认 YES - */ -@property (nonatomic, assign) BOOL allowSlideSelect; - -/** - 根据需要设置自身需要的裁剪比例 - - @discussion e.g.:1:1,请使用ZLDefine中所提供方法 GetClipRatio(NSInteger value1, NSInteger value2),该数组可不设置,有默认比例,为(Custom, 1:1, 4:3, 3:2, 16:9) - */ -@property (nonatomic, strong) NSArray *clipRatios; - -/** - 在小图界面选择图片后直接进入编辑界面,默认NO, 仅在allowEditImage为YES且maxSelectCount为1 的情况下,置为YES有效 - */ -@property (nonatomic, assign) BOOL editAfterSelectThumbnailImage; - -/** - 是否在相册内部拍照按钮上面实时显示相机俘获的影像 默认 YES - */ -@property (nonatomic, assign) BOOL showCaptureImageOnTakePhotoBtn; - -/** - 是否升序排列,预览界面不受该参数影响,默认升序 YES - */ -@property (nonatomic, assign) BOOL sortAscending; - -/** - 控制单选模式下,是否显示选择按钮,默认 NO,多选模式不受控制 - */ -@property (nonatomic, assign) BOOL showSelectBtn; - /** 是否选择了原图 */ @@ -129,59 +24,9 @@ @property (nonatomic, copy) NSMutableArray *arrSelectedModels; /** - 导航条颜色,默认 rgb(19, 153, 231) - */ -@property (nonatomic, strong) UIColor *navBarColor; - -/** - 导航标题颜色,默认 rgb(255, 255, 255) - */ -@property (nonatomic, strong) UIColor *navTitleColor; - -/** - 底部工具条底色,默认 rgb(255, 255, 255) - */ -@property (nonatomic, strong) UIColor *bottomViewBgColor; - -/** - 底部工具栏按钮 可交互 状态标题颜色,底部 toolbar 按钮可交互状态title颜色均使用这个,确定按钮 可交互 的背景色为这个,默认rgb(80, 180, 234) - */ -@property (nonatomic, strong) UIColor *bottomBtnsNormalTitleColor; - -/** - 底部工具栏按钮 不可交互 状态标题颜色,底部 toolbar 按钮不可交互状态颜色均使用这个,确定按钮 不可交互 的背景色为这个,默认rgb(200, 200, 200) - */ -@property (nonatomic, strong) UIColor *bottomBtnsDisableBgColor; - -/** - 是否在已选择的图片上方覆盖一层已选中遮罩层,默认 NO - */ -@property (nonatomic, assign) BOOL showSelectedMask; - -/** - 遮罩层颜色,内部会默认调整颜色的透明度为0.2, 默认 blackColor - */ -@property (nonatomic, strong) UIColor *selectedMaskColor; - -/** - 使用系统相机,默认NO(系统相机则只能进行拍照) - */ -@property (nonatomic, assign) BOOL useSystemCamera; - -/** - 是否允许录制视频(当useSystemCamera为YES时无效),默认YES - */ -@property (nonatomic, assign) BOOL allowRecordVideo; - -/** - 视频清晰度,默认ZLCaptureSessionPreset1280x720 - */ -@property (nonatomic, assign) ZLCaptureSessionPreset sessionPreset; - -/** - 最大录制时长,默认 10s + 相册框架配置 */ -@property (nonatomic, assign) NSInteger maxRecordDuration; +@property (nonatomic, strong) ZLPhotoConfiguration *configuration; /** 点击确定选择照片回调 diff --git a/PhotoBrowser/ZLPhotoBrowser.m b/PhotoBrowser/ZLPhotoBrowser.m index 2b85cc91..fccd7d34 100644 --- a/PhotoBrowser/ZLPhotoBrowser.m +++ b/PhotoBrowser/ZLPhotoBrowser.m @@ -31,18 +31,6 @@ - (instancetype)initWithRootViewController:(UIViewController *)rootViewControlle return self; } -- (UIImage *)imageWithColor:(UIColor *)color -{ - CGRect rect = CGRectMake(0, 0, 1, 1); - UIGraphicsBeginImageContext(rect.size); - CGContextRef context = UIGraphicsGetCurrentContext(); - CGContextSetFillColorWithColor(context, [color CGColor]); - CGContextFillRect(context, rect); - UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext(); - UIGraphicsEndImageContext(); - return theImage; -} - - (NSMutableArray *)arrSelectedModels { if (!_arrSelectedModels) { @@ -51,52 +39,33 @@ - (UIImage *)imageWithColor:(UIColor *)color return _arrSelectedModels; } -- (NSArray *)clipRatios -{ - if (_clipRatios) { - return _clipRatios; - } else { - return @[GetCustomClipRatio(), - GetClipRatio(1, 1), - GetClipRatio(4, 3), - GetClipRatio(3, 2), - GetClipRatio(16, 9)]; - } -} - -- (void)setNavBarColor:(UIColor *)navBarColor -{ - _navBarColor = navBarColor?:kNavBar_color; - [self.navigationBar setBackgroundImage:[self imageWithColor:_navBarColor] forBarMetrics:UIBarMetricsDefault]; -} - -- (void)setNavTitleColor:(UIColor *)navTitleColor -{ - _navTitleColor = navTitleColor?:kNavBar_tintColor; - [self.navigationBar setTintColor:_navTitleColor]; - [self.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: _navTitleColor}]; -} - -- (void)setBottomViewBgColor:(UIColor *)bottomViewBgColor +- (void)setConfiguration:(ZLPhotoConfiguration *)configuration { - _bottomViewBgColor = bottomViewBgColor?:kBottomViewBgColor; -} - -- (void)setBottomBtnsNormalTitleColor:(UIColor *)bottomBtnsNormalTitleColor -{ - _bottomBtnsNormalTitleColor = bottomBtnsNormalTitleColor?:kBottomBtnsNormalTitleColor; + _configuration = configuration; + + [UIApplication sharedApplication].statusBarStyle = self.configuration.statusBarStyle; + [self.navigationBar setBackgroundImage:[self imageWithColor:configuration.navBarColor] forBarMetrics:UIBarMetricsDefault]; + [self.navigationBar setTintColor:configuration.navTitleColor]; + [self.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: configuration.navTitleColor}]; } -- (void)setBottomBtnsDisableBgColor:(UIColor *)bottomBtnsDisableBgColor +- (UIImage *)imageWithColor:(UIColor *)color { - _bottomBtnsDisableBgColor = bottomBtnsDisableBgColor?:kBottomBtnsDisableTitleColor; + CGRect rect = CGRectMake(0, 0, 1, 1); + UIGraphicsBeginImageContext(rect.size); + CGContextRef context = UIGraphicsGetCurrentContext(); + CGContextSetFillColorWithColor(context, [color CGColor]); + CGContextFillRect(context, rect); + UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + return theImage; } -- (void)viewWillAppear:(BOOL)animated -{ - [super viewWillAppear:animated]; - [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent; -} +//- (void)viewWillAppear:(BOOL)animated +//{ +// [super viewWillAppear:animated]; +// [UIApplication sharedApplication].statusBarStyle = self.configuration.statusBarStyle; +//} - (void)viewWillDisappear:(BOOL)animated { @@ -178,9 +147,9 @@ - (void)viewWillAppear:(BOOL)animated [super viewWillAppear:animated]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; + ZLPhotoConfiguration *configuration = [(ZLImageNavigationController *)self.navigationController configuration]; zl_weakify(self); - [ZLPhotoManager getPhotoAblumList:nav.allowSelectVideo allowSelectImage:nav.allowSelectImage complete:^(NSArray *albums) { + [ZLPhotoManager getPhotoAblumList:configuration.allowSelectVideo allowSelectImage:configuration.allowSelectImage complete:^(NSArray *albums) { zl_strongify(weakSelf); strongSelf.arrayDataSources = [NSMutableArray arrayWithArray:albums]; dispatch_async(dispatch_get_main_queue(), ^{ @@ -192,13 +161,14 @@ - (void)viewWillAppear:(BOOL)animated - (void)initNavBtn { - ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; + ZLPhotoConfiguration *configuration = [(ZLImageNavigationController *)self.navigationController configuration]; + UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; CGFloat width = GetMatchValue(GetLocalLanguageTextValue(ZLPhotoBrowserCancelText), 16, YES, 44); btn.frame = CGRectMake(0, 0, width, 44); btn.titleLabel.font = [UIFont systemFontOfSize:16]; [btn setTitle:GetLocalLanguageTextValue(ZLPhotoBrowserCancelText) forState:UIControlStateNormal]; - [btn setTitleColor:nav.navTitleColor forState:UIControlStateNormal]; + [btn setTitleColor:configuration.navTitleColor forState:UIControlStateNormal]; [btn addTarget:self action:@selector(navRightBtn_Click) forControlEvents:UIControlEventTouchUpInside]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn]; } @@ -242,8 +212,9 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N ZLAlbumListModel *albumModel = self.arrayDataSources[indexPath.row]; - ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; - cell.cornerRadio = nav.cellCornerRadio; + ZLPhotoConfiguration *configuration = [(ZLImageNavigationController *)self.navigationController configuration]; + + cell.cornerRadio = configuration.cellCornerRadio; cell.model = albumModel; diff --git a/PhotoBrowser/ZLPhotoConfiguration.h b/PhotoBrowser/ZLPhotoConfiguration.h new file mode 100644 index 00000000..f45136f1 --- /dev/null +++ b/PhotoBrowser/ZLPhotoConfiguration.h @@ -0,0 +1,224 @@ +// +// ZLPhotoConfiguration.h +// ZLPhotoBrowser +// +// Created by long on 2017/11/16. +// Copyright © 2017年 long. All rights reserved. +// + +#import +#import "ZLDefine.h" + +@class PHAsset; + +@interface ZLPhotoConfiguration : NSObject + +- (instancetype)init NS_UNAVAILABLE; + + +/** + 默认相册配置 + */ ++ (instancetype)defaultPhotoConfiguration; + + +/** + 状态栏样式 默认 UIStatusBarStyleLightContent + + @discussion 需要在info.plist中添加键 "View controller-based status bar appearance" 值设置为 "NO" + */ +@property (nonatomic, assign) UIStatusBarStyle statusBarStyle; + +/** + 最大选择数 默认9张,最小 1 + */ +@property (nonatomic, assign) NSInteger maxSelectCount; + +/** + 预览图最大显示数 默认20张 + */ +@property (nonatomic, assign) NSInteger maxPreviewCount; + +/** + cell的圆角弧度 默认为0 + */ +@property (nonatomic, assign) CGFloat cellCornerRadio; + +/** + 是否允许混合选择,即可以同时选择image(image/gif/livephoto)、video类型, 默认YES + */ +@property (nonatomic, assign) BOOL allowMixSelect; + +/** + 是否允许选择照片 默认YES + */ +@property (nonatomic, assign) BOOL allowSelectImage; + +/** + 是否允许选择视频 默认YES + */ +@property (nonatomic, assign) BOOL allowSelectVideo; + +/** + 是否允许选择Gif,只是控制是否选择,并不控制是否显示,如果为NO,则不显示gif标识 默认YES + */ +@property (nonatomic, assign) BOOL allowSelectGif; + +/** + 是否允许选择Live Photo,只是控制是否选择,并不控制是否显示,如果为NO,则不显示Live Photo标识 默认NO + + @warning ios9 以上系统支持 + */ +@property (nonatomic, assign) BOOL allowSelectLivePhoto; + +/** + 是否允许相册内部拍照 默认YES + */ +@property (nonatomic, assign) BOOL allowTakePhotoInLibrary; + +/** + 是否允许Force Touch功能 默认YES + */ +@property (nonatomic, assign) BOOL allowForceTouch; + +/** + 是否允许编辑图片,选择一张时候才允许编辑,默认YES + */ +@property (nonatomic, assign) BOOL allowEditImage; + +/** + 是否允许编辑视频,选择一张时候才允许编辑,默认NO + */ +@property (nonatomic, assign) BOOL allowEditVideo; + +/** + 是否允许选择原图,默认YES + */ +@property (nonatomic, assign) BOOL allowSelectOriginal; + +/** + 编辑视频时最大裁剪时间,单位:秒,默认10s 且最低10s + + @discussion 当该参数为10s时,所选视频时长必须大于等于10s才允许进行编辑 + */ +@property (nonatomic, assign) NSInteger maxEditVideoTime; + +/** + 允许选择视频的最大时长,单位:秒, 默认 120s + */ +@property (nonatomic, assign) NSInteger maxVideoDuration; + +/** + 是否允许滑动选择 默认 YES + */ +@property (nonatomic, assign) BOOL allowSlideSelect; + +/** + 预览界面是否允许拖拽选择 默认 NO + */ +@property (nonatomic, assign) BOOL allowDragSelect; + +/** + 根据需要设置自身需要的裁剪比例 + + @discussion e.g.:1:1,请使用ZLDefine中所提供方法 GetClipRatio(NSInteger value1, NSInteger value2),该数组可不设置,有默认比例,为(Custom, 1:1, 4:3, 3:2, 16:9) + */ +@property (nonatomic, strong) NSArray *clipRatios; + +/** + 在小图界面选择 图片/视频 后直接进入编辑界面,默认NO + + @discussion 编辑图片 仅在allowEditImage为YES 且 maxSelectCount为1 的情况下,置为YES有效,编辑视频则在 allowEditVideo为YES 且 maxSelectCount为1情况下,置为YES有效 + */ +@property (nonatomic, assign) BOOL editAfterSelectThumbnailImage; + +/** + 是否在相册内部拍照按钮上面实时显示相机俘获的影像 默认 YES + */ +@property (nonatomic, assign) BOOL showCaptureImageOnTakePhotoBtn; + +/** + 是否升序排列,预览界面不受该参数影响,默认升序 YES + */ +@property (nonatomic, assign) BOOL sortAscending; + +/** + 控制单选模式下,是否显示选择按钮,默认 NO,多选模式不受控制 + */ +@property (nonatomic, assign) BOOL showSelectBtn; + +/** + 导航条颜色,默认 rgb(19, 153, 231) + */ +@property (nonatomic, strong) UIColor *navBarColor; + +/** + 导航标题颜色,默认 rgb(255, 255, 255) + */ +@property (nonatomic, strong) UIColor *navTitleColor; + +/** + 底部工具条底色,默认 rgb(255, 255, 255) + */ +@property (nonatomic, strong) UIColor *bottomViewBgColor; + +/** + 底部工具栏按钮 可交互 状态标题颜色,底部 toolbar 按钮可交互状态title颜色均使用这个,确定按钮 可交互 的背景色为这个,默认rgb(80, 180, 234) + */ +@property (nonatomic, strong) UIColor *bottomBtnsNormalTitleColor; + +/** + 底部工具栏按钮 不可交互 状态标题颜色,底部 toolbar 按钮不可交互状态颜色均使用这个,确定按钮 不可交互 的背景色为这个,默认rgb(200, 200, 200) + */ +@property (nonatomic, strong) UIColor *bottomBtnsDisableBgColor; + +/** + 是否在已选择的图片上方覆盖一层已选中遮罩层,默认 NO + */ +@property (nonatomic, assign) BOOL showSelectedMask; + +/** + 遮罩层颜色,内部会默认调整颜色的透明度为0.2, 默认 blackColor + */ +@property (nonatomic, strong) UIColor *selectedMaskColor; + +/** + 支持开发者自定义图片,但是所自定义图片资源名称必须与被替换的bundle中的图片名称一致 + @example: 开发者需要替换选中与未选中的图片资源,则需要传入的数组为 @[@"btn_selected", @"btn_unselected"],则框架内会使用开发者项目中的图片资源,而其他图片则用框架bundle中的资源 + */ +@property (nonatomic, strong) NSArray *customImageNames; + +/** + 回调时候是否允许框架解析图片,默认YES + + @discussion 如果选择了大量图片,框架一下解析大量图片会耗费一些内存,开发者此时可置为NO,拿到assets数组后使用 ZLPhotoManager 中提供的 "anialysisAssets:original:completion:" 方法进行逐个解析,以达到缓解内存瞬间暴涨的效果,该值为NO时,回调的图片数组为nil + */ +@property (nonatomic, assign) BOOL shouldAnialysisAsset; + +/** + 框架语言,默认 ZLLanguageSystem (跟随系统语言) + 仅切换框架内定义的语言,由于相册名字根据系统语言进行获取,所以相册列表界面为当前系统语言 + */ +@property (nonatomic, assign) ZLLanguageType languageType; + +/** + 使用系统相机,默认NO(系统相机则只能进行拍照) + */ +@property (nonatomic, assign) BOOL useSystemCamera; + +/** + 是否允许录制视频(当useSystemCamera为YES时无效),默认YES + */ +@property (nonatomic, assign) BOOL allowRecordVideo; + +/** + 最大录制时长,默认 10s,最小为 1s + */ +@property (nonatomic, assign) NSInteger maxRecordDuration; + +/** + 视频清晰度,默认ZLCaptureSessionPreset1280x720 + */ +@property (nonatomic, assign) ZLCaptureSessionPreset sessionPreset; + +@end diff --git a/PhotoBrowser/ZLPhotoConfiguration.m b/PhotoBrowser/ZLPhotoConfiguration.m new file mode 100644 index 00000000..73977cab --- /dev/null +++ b/PhotoBrowser/ZLPhotoConfiguration.m @@ -0,0 +1,121 @@ +// +// ZLPhotoConfiguration.m +// ZLPhotoBrowser +// +// Created by long on 2017/11/16. +// Copyright © 2017年 long. All rights reserved. +// + +#import "ZLPhotoConfiguration.h" + +@implementation ZLPhotoConfiguration + +- (void)dealloc +{ + [[NSUserDefaults standardUserDefaults] removeObjectForKey:ZLCustomImageNames]; + [[NSUserDefaults standardUserDefaults] removeObjectForKey:ZLLanguageTypeKey]; + [[NSUserDefaults standardUserDefaults] synchronize]; +// NSLog(@"---- %s", __FUNCTION__); +} + ++ (instancetype)defaultPhotoConfiguration +{ + ZLPhotoConfiguration *configuration = [ZLPhotoConfiguration new]; + + configuration.statusBarStyle = UIStatusBarStyleLightContent; + configuration.maxSelectCount = 9; + configuration.maxPreviewCount = 20; + configuration.cellCornerRadio = .0; + configuration.allowMixSelect = YES; + configuration.allowSelectImage = YES; + configuration.allowSelectVideo = YES; + configuration.allowSelectGif = YES; + configuration.allowSelectLivePhoto = NO; + configuration.allowTakePhotoInLibrary = YES; + configuration.allowForceTouch = YES; + configuration.allowEditImage = YES; + configuration.allowEditVideo = NO; + configuration.allowSelectOriginal = YES; + configuration.maxEditVideoTime = 10; + configuration.maxVideoDuration = 120; + configuration.allowSlideSelect = YES; + configuration.allowDragSelect = NO; + configuration.clipRatios = @[GetCustomClipRatio(), + GetClipRatio(1, 1), + GetClipRatio(4, 3), + GetClipRatio(3, 2), + GetClipRatio(16, 9)]; + configuration.editAfterSelectThumbnailImage = NO; + configuration.showCaptureImageOnTakePhotoBtn = YES; + configuration.sortAscending = YES; + configuration.showSelectBtn = NO; + configuration.navBarColor = kRGB(19, 153, 231); + configuration.navTitleColor = [UIColor whiteColor]; + configuration.bottomViewBgColor = [UIColor whiteColor]; + configuration.bottomBtnsNormalTitleColor = kRGB(80, 180, 234); + configuration.bottomBtnsDisableBgColor = kRGB(200, 200, 200); + configuration.showSelectedMask = NO; + configuration.selectedMaskColor = [UIColor blackColor]; + configuration.customImageNames = nil; + configuration.shouldAnialysisAsset = YES; + configuration.languageType = ZLLanguageSystem; + configuration.useSystemCamera = NO; + configuration.allowRecordVideo = YES; + configuration.maxRecordDuration = 10; + configuration.sessionPreset = ZLCaptureSessionPreset1280x720; + + return configuration; +} + +- (void)setMaxSelectCount:(NSInteger)maxSelectCount +{ + _maxSelectCount = MAX(maxSelectCount, 1); + + if (maxSelectCount > 1) { + _showSelectBtn = YES; + } +} + +- (void)setShowSelectBtn:(BOOL)showSelectBtn +{ + if (self.maxSelectCount > 1) { + _showSelectBtn = YES; + } else { + _showSelectBtn = showSelectBtn; + } +} + +- (void)setAllowSelectLivePhoto:(BOOL)allowSelectLivePhoto +{ + if (@available(iOS 9.0, *)) { + _allowSelectLivePhoto = allowSelectLivePhoto; + } else { + _allowSelectLivePhoto = NO; + } +} + +- (void)setMaxEditVideoTime:(NSInteger)maxEditVideoTime +{ + _maxEditVideoTime = MAX(maxEditVideoTime, 10); +} + +- (void)setCustomImageNames:(NSArray *)customImageNames +{ + _customImageNames = customImageNames; + [[NSUserDefaults standardUserDefaults] setValue:customImageNames forKey:ZLCustomImageNames]; + [[NSUserDefaults standardUserDefaults] synchronize]; +} + +- (void)setLanguageType:(ZLLanguageType)languageType +{ + [[NSUserDefaults standardUserDefaults] setValue:@(languageType) forKey:ZLLanguageTypeKey]; + [[NSUserDefaults standardUserDefaults] synchronize]; + [NSBundle resetLanguage]; +} + +- (void)setMaxRecordDuration:(NSInteger)maxRecordDuration +{ + _maxRecordDuration = MAX(maxRecordDuration, 1); +} + +@end diff --git a/PhotoBrowser/ZLPlayer.m b/PhotoBrowser/ZLPlayer.m index f10dce1c..e7617c20 100644 --- a/PhotoBrowser/ZLPlayer.m +++ b/PhotoBrowser/ZLPlayer.m @@ -23,7 +23,7 @@ - (void)dealloc [self removeObserver]; [_player pause]; _player = nil; -// NSLog(@"%s", __func__); +// NSLog(@"---- %s", __FUNCTION__); } - (instancetype)initWithFrame:(CGRect)frame diff --git a/PhotoBrowser/ZLShowBigImgViewController.h b/PhotoBrowser/ZLShowBigImgViewController.h index 3fb57874..77068f06 100644 --- a/PhotoBrowser/ZLShowBigImgViewController.h +++ b/PhotoBrowser/ZLShowBigImgViewController.h @@ -27,9 +27,12 @@ @property (nonatomic, assign) BOOL hideToolBar; //预览相册图片回调 -@property (nonatomic, copy) void (^btnDonePreviewBlock)(NSArray *, NSArray *); +@property (nonatomic, copy) void (^previewSelectedImageBlock)(NSArray *arrP, NSArray *arrA); //预览网络图片回调 @property (nonatomic, copy) void (^previewNetImageBlock)(NSArray *photos); +//预览 相册/网络 图片时候,点击返回回调 +@property (nonatomic, copy) void (^cancelPreviewBlock)(void); + @end diff --git a/PhotoBrowser/ZLShowBigImgViewController.m b/PhotoBrowser/ZLShowBigImgViewController.m index 22334083..0de20b62 100644 --- a/PhotoBrowser/ZLShowBigImgViewController.m +++ b/PhotoBrowser/ZLShowBigImgViewController.m @@ -176,9 +176,10 @@ - (void)setArrSelPhotos:(NSMutableArray *)arrSelPhotos - (void)initNavView { - ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; + ZLPhotoConfiguration *configuration = [(ZLImageNavigationController *)self.navigationController configuration]; + _navView = [[UIView alloc] init]; - _navView.backgroundColor = [nav.navBarColor colorWithAlphaComponent:.9]; + _navView.backgroundColor = [configuration.navBarColor colorWithAlphaComponent:.9]; [self.view addSubview:_navView]; _btnBack = [UIButton buttonWithType:UIButtonTypeCustom]; @@ -189,12 +190,12 @@ - (void)initNavView _indexLabel = [[UILabel alloc] init]; _indexLabel.font = [UIFont systemFontOfSize:18]; - _indexLabel.textColor = nav.navTitleColor; + _indexLabel.textColor = configuration.navTitleColor; _indexLabel.textAlignment = NSTextAlignmentCenter; _indexLabel.text = [NSString stringWithFormat:@"%ld/%ld", _currentPage, self.models.count]; [_navView addSubview:_indexLabel]; - if (!nav.showSelectBtn || self.hideToolBar) { + if (!configuration.showSelectBtn || self.hideToolBar) { return; } @@ -236,15 +237,16 @@ - (void)initBottomView if (self.hideToolBar) return; ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; + ZLPhotoConfiguration *configuration = nav.configuration; _bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, kViewHeight - 44, kViewWidth, 44)]; - _bottomView.backgroundColor = nav.bottomViewBgColor; + _bottomView.backgroundColor = configuration.bottomViewBgColor; - if (nav.allowSelectOriginal) { + if (configuration.allowSelectOriginal) { _btnOriginalPhoto = [UIButton buttonWithType:UIButtonTypeCustom]; [_btnOriginalPhoto setTitle:GetLocalLanguageTextValue(ZLPhotoBrowserOriginalText) forState:UIControlStateNormal]; _btnOriginalPhoto.titleLabel.font = [UIFont systemFontOfSize:15]; - [_btnOriginalPhoto setTitleColor:nav.bottomBtnsNormalTitleColor forState: UIControlStateNormal]; + [_btnOriginalPhoto setTitleColor:configuration.bottomBtnsNormalTitleColor forState: UIControlStateNormal]; UIImage *normalImg = GetImageWithName(@"btn_original_circle"); UIImage *selImg = GetImageWithName(@"btn_selected"); [_btnOriginalPhoto setImage:normalImg forState:UIControlStateNormal]; @@ -257,7 +259,7 @@ - (void)initBottomView self.labPhotosBytes = [[UILabel alloc] init]; self.labPhotosBytes.font = [UIFont systemFontOfSize:15]; - self.labPhotosBytes.textColor = nav.bottomBtnsNormalTitleColor; + self.labPhotosBytes.textColor = configuration.bottomBtnsNormalTitleColor; [_bottomView addSubview:self.labPhotosBytes]; } @@ -265,7 +267,7 @@ - (void)initBottomView _btnEdit = [UIButton buttonWithType:UIButtonTypeCustom]; [_btnEdit setTitle:GetLocalLanguageTextValue(ZLPhotoBrowserEditText) forState:UIControlStateNormal]; _btnEdit.titleLabel.font = [UIFont systemFontOfSize:15]; - [_btnEdit setTitleColor:nav.bottomBtnsNormalTitleColor forState:UIControlStateNormal]; + [_btnEdit setTitleColor:configuration.bottomBtnsNormalTitleColor forState:UIControlStateNormal]; _btnEdit.frame = CGRectMake(kViewWidth/2-30, 7, 60, 30); [_btnEdit addTarget:self action:@selector(btnEdit_Click:) forControlEvents:UIControlEventTouchUpInside]; [_bottomView addSubview:_btnEdit]; @@ -276,7 +278,7 @@ - (void)initBottomView _btnDone.layer.masksToBounds = YES; _btnDone.layer.cornerRadius = 3.0f; [_btnDone setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; - [_btnDone setBackgroundColor:nav.bottomBtnsNormalTitleColor]; + [_btnDone setBackgroundColor:configuration.bottomBtnsNormalTitleColor]; _btnDone.frame = CGRectMake(kViewWidth - 82, 7, 70, 30); [_btnDone addTarget:self action:@selector(btnDone_Click:) forControlEvents:UIControlEventTouchUpInside]; [_bottomView addSubview:_btnDone]; @@ -287,7 +289,7 @@ - (void)initBottomView //预览用户已确定选择的照片,隐藏原图按钮 _btnOriginalPhoto.hidden = YES; } - if (!nav.allowEditImage && !nav.allowEditVideo) { + if (!configuration.allowEditImage && !configuration.allowEditVideo) { _btnEdit.hidden = YES; } } @@ -296,12 +298,14 @@ - (void)initBottomView - (void)btnOriginalImage_Click:(UIButton *)btn { ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; + ZLPhotoConfiguration *configuration = nav.configuration; + nav.isSelectOriginalPhoto = btn.selected = !btn.selected; if (btn.selected) { [self getPhotosBytes]; if (!_navRightBtn.isSelected) { - if (nav.showSelectBtn && - nav.arrSelectedModels.count < nav.maxSelectCount) { + if (configuration.showSelectBtn && + nav.arrSelectedModels.count < configuration.maxSelectCount) { [self navRightBtn_Click:_navRightBtn]; } } @@ -313,8 +317,10 @@ - (void)btnOriginalImage_Click:(UIButton *)btn - (void)btnEdit_Click:(UIButton *)btn { ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; - BOOL flag = !_navRightBtn.isSelected && nav.showSelectBtn && - nav.arrSelectedModels.count < nav.maxSelectCount; + ZLPhotoConfiguration *configuration = nav.configuration; + + BOOL flag = !_navRightBtn.isSelected && configuration.showSelectBtn && + nav.arrSelectedModels.count < configuration.maxSelectCount; ZLPhotoModel *model = self.models[_currentPage-1]; if (flag) { @@ -329,8 +335,8 @@ - (void)btnEdit_Click:(UIButton *)btn vc.model = model; [self.navigationController pushViewController:vc animated:NO]; } else if (model.type == ZLAssetMediaTypeImage || - (model.type == ZLAssetMediaTypeGif && !nav.allowSelectGif) || - (model.type == ZLAssetMediaTypeLivePhoto && !nav.allowSelectLivePhoto)) { + (model.type == ZLAssetMediaTypeGif && !configuration.allowSelectGif) || + (model.type == ZLAssetMediaTypeLivePhoto && !configuration.allowSelectLivePhoto)) { ZLEditViewController *vc = [[ZLEditViewController alloc] init]; vc.model = model; ZLBigImageCell *cell = (ZLBigImageCell *)[_collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForRow:_currentPage-1 inSection:0]]; @@ -342,21 +348,23 @@ - (void)btnEdit_Click:(UIButton *)btn - (void)btnDone_Click:(UIButton *)btn { ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; + ZLPhotoConfiguration *configuration = nav.configuration; + if (!self.arrSelPhotos && nav.arrSelectedModels.count == 0) { ZLPhotoModel *model = self.models[_currentPage-1]; if (![ZLPhotoManager judgeAssetisInLocalAblum:model.asset]) { ShowToastLong(@"%@", GetLocalLanguageTextValue(ZLPhotoBrowserLoadingText)); return; } - if (model.type == ZLAssetMediaTypeVideo && GetDuration(model.duration) > nav.maxVideoDuration) { - ShowToastLong(GetLocalLanguageTextValue(ZLPhotoBrowserMaxVideoDurationText), nav.maxVideoDuration); + if (model.type == ZLAssetMediaTypeVideo && GetDuration(model.duration) > configuration.maxVideoDuration) { + ShowToastLong(GetLocalLanguageTextValue(ZLPhotoBrowserMaxVideoDurationText), configuration.maxVideoDuration); return; } [nav.arrSelectedModels addObject:model]; } - if (self.arrSelPhotos && self.btnDonePreviewBlock) { - self.btnDonePreviewBlock(self.arrSelPhotos, _arrSelAssets); + if (self.arrSelPhotos && self.previewSelectedImageBlock) { + self.previewSelectedImageBlock(self.arrSelPhotos, _arrSelAssets); } else if (self.arrSelPhotos && self.previewNetImageBlock) { self.previewNetImageBlock(self.arrSelPhotos); } else if (nav.callSelectImageBlock) { @@ -371,6 +379,10 @@ - (void)btnBack_Click self.btnBackBlock(nav.arrSelectedModels, nav.isSelectOriginalPhoto); } + if (self.cancelPreviewBlock) { + self.cancelPreviewBlock(); + } + UIViewController *vc = [self.navigationController popViewControllerAnimated:YES]; //由于collectionView的frame的width是大于该界面的width,所以设置这个颜色是为了pop时候隐藏collectionView的黑色背景 _collectionView.backgroundColor = [UIColor clearColor]; @@ -382,21 +394,22 @@ - (void)btnBack_Click - (void)navRightBtn_Click:(UIButton *)btn { ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; + ZLPhotoConfiguration *configuration = nav.configuration; ZLPhotoModel *model = self.models[_currentPage-1]; if (!btn.selected) { //选中 [btn.layer addAnimation:GetBtnStatusChangedAnimation() forKey:nil]; - if (nav.arrSelectedModels.count >= nav.maxSelectCount) { - ShowToastLong(GetLocalLanguageTextValue(ZLPhotoBrowserMaxSelectCountText), nav.maxSelectCount); + if (nav.arrSelectedModels.count >= configuration.maxSelectCount) { + ShowToastLong(GetLocalLanguageTextValue(ZLPhotoBrowserMaxSelectCountText), configuration.maxSelectCount); return; } if (model.asset && ![ZLPhotoManager judgeAssetisInLocalAblum:model.asset]) { ShowToastLong(@"%@", GetLocalLanguageTextValue(ZLPhotoBrowserLoadingText)); return; } - if (model.type == ZLAssetMediaTypeVideo && GetDuration(model.duration) > nav.maxVideoDuration) { - ShowToastLong(GetLocalLanguageTextValue(ZLPhotoBrowserMaxVideoDurationText), nav.maxVideoDuration); + if (model.type == ZLAssetMediaTypeVideo && GetDuration(model.duration) > configuration.maxVideoDuration) { + ShowToastLong(GetLocalLanguageTextValue(ZLPhotoBrowserMaxVideoDurationText), configuration.maxVideoDuration); return; } @@ -470,7 +483,9 @@ - (void)resetDontBtnState - (void)resetEditBtnState { ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; - if (!nav.allowEditImage && !nav.allowEditVideo) return; + ZLPhotoConfiguration *configuration = nav.configuration; + + if (!configuration.allowEditImage && !configuration.allowEditVideo) return; ZLPhotoModel *m = self.models[_currentPage-1]; BOOL flag = [m.asset.localIdentifier isEqualToString:nav.arrSelectedModels.firstObject.asset.localIdentifier]; @@ -478,12 +493,12 @@ - (void)resetEditBtnState if ((nav.arrSelectedModels.count == 0 || (nav.arrSelectedModels.count <= 1 && flag)) && - ((nav.allowEditImage && + ((configuration.allowEditImage && (m.type == ZLAssetMediaTypeImage || - (m.type == ZLAssetMediaTypeGif && !nav.allowSelectGif) || - (m.type == ZLAssetMediaTypeLivePhoto && !nav.allowSelectLivePhoto))) || + (m.type == ZLAssetMediaTypeGif && !configuration.allowSelectGif) || + (m.type == ZLAssetMediaTypeLivePhoto && !configuration.allowSelectLivePhoto))) || - (nav.allowEditVideo && m.type == ZLAssetMediaTypeVideo && round(m.asset.duration) >= nav.maxEditVideoTime))) { + (configuration.allowEditVideo && m.type == ZLAssetMediaTypeVideo && round(m.asset.duration) >= configuration.maxEditVideoTime))) { _btnEdit.hidden = NO; } else { _btnEdit.hidden = YES; @@ -492,17 +507,18 @@ - (void)resetEditBtnState - (void)resetOriginalBtnState { - ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; + ZLPhotoConfiguration *configuration = [(ZLImageNavigationController *)self.navigationController configuration]; + ZLPhotoModel *m = self.models[_currentPage-1]; if ((m.type == ZLAssetMediaTypeImage) || - (m.type == ZLAssetMediaTypeGif && !nav.allowSelectGif) || - (m.type == ZLAssetMediaTypeLivePhoto && !nav.allowSelectLivePhoto)) { + (m.type == ZLAssetMediaTypeGif && !configuration.allowSelectGif) || + (m.type == ZLAssetMediaTypeLivePhoto && !configuration.allowSelectLivePhoto)) { _btnOriginalPhoto.hidden = NO; self.labPhotosBytes.hidden = NO; - } else { - _btnOriginalPhoto.hidden = YES; - self.labPhotosBytes.hidden = YES; - } + } else { + _btnOriginalPhoto.hidden = YES; + self.labPhotosBytes.hidden = YES; + } } - (void)getPhotosBytes @@ -510,7 +526,9 @@ - (void)getPhotosBytes ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; if (!nav.isSelectOriginalPhoto) return; - NSArray *arr = nav.showSelectBtn?nav.arrSelectedModels:@[self.models[_currentPage-1]]; + ZLPhotoConfiguration *configuration = nav.configuration; + + NSArray *arr = configuration.showSelectBtn?nav.arrSelectedModels:@[self.models[_currentPage-1]]; if (arr.count) { zl_weakify(self); @@ -558,10 +576,10 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell ZLBigImageCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ZLBigImageCell" forIndexPath:indexPath]; ZLPhotoModel *model = self.models[indexPath.row]; - ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; + ZLPhotoConfiguration *configuration = [(ZLImageNavigationController *)self.navigationController configuration]; - cell.showGif = nav.allowSelectGif; - cell.showLivePhoto = nav.allowSelectLivePhoto; + cell.showGif = configuration.allowSelectGif; + cell.showLivePhoto = configuration.allowSelectLivePhoto; cell.model = model; zl_weakify(self); cell.singleTapCallBack = ^() { @@ -606,8 +624,8 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { //单选模式下获取当前图片大小 - ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; - if (!nav.showSelectBtn) [self getPhotosBytes]; + ZLPhotoConfiguration *configuration = [(ZLImageNavigationController *)self.navigationController configuration]; + if (!configuration.showSelectBtn) [self getPhotosBytes]; [self reloadCurrentCell]; } diff --git a/PhotoBrowser/ZLThumbnailViewController.m b/PhotoBrowser/ZLThumbnailViewController.m index a785026b..e3ae141a 100644 --- a/PhotoBrowser/ZLThumbnailViewController.m +++ b/PhotoBrowser/ZLThumbnailViewController.m @@ -61,8 +61,8 @@ @implementation ZLThumbnailViewController - (void)dealloc { -// NSLog(@"---- %s", __FUNCTION__); [[NSNotificationCenter defaultCenter] removeObserver:self]; +// NSLog(@"---- %s", __FUNCTION__); } - (NSMutableArray *)arrDataSources @@ -70,11 +70,14 @@ - (void)dealloc if (!_arrDataSources) { ZLProgressHUD *hud = [[ZLProgressHUD alloc] init]; [hud show]; + ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; + ZLPhotoConfiguration *configuration = nav.configuration; + if (!_albumListModel) { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ zl_weakify(self); - [ZLPhotoManager getCameraRollAlbumList:nav.allowSelectVideo allowSelectImage:nav.allowSelectImage complete:^(ZLAlbumListModel *album) { + [ZLPhotoManager getCameraRollAlbumList:configuration.allowSelectVideo allowSelectImage:configuration.allowSelectImage complete:^(ZLAlbumListModel *album) { zl_strongify(weakSelf); ZLImageNavigationController *weakNav = (ZLImageNavigationController *)strongSelf.navigationController; @@ -83,7 +86,7 @@ - (void)dealloc strongSelf.arrDataSources = [NSMutableArray arrayWithArray:strongSelf.albumListModel.models]; [hud hide]; dispatch_async(dispatch_get_main_queue(), ^{ - if (weakNav.allowTakePhotoInLibrary && weakNav.allowSelectImage) { + if (configuration.allowTakePhotoInLibrary && configuration.allowSelectImage) { strongSelf.allowTakePhoto = YES; } strongSelf.title = album.title; @@ -93,7 +96,7 @@ - (void)dealloc }]; }); } else { - if (nav.allowTakePhotoInLibrary && nav.allowSelectImage && self.albumListModel.isCameraRoll) { + if (configuration.allowTakePhotoInLibrary && configuration.allowSelectImage && self.albumListModel.isCameraRoll) { self.allowTakePhoto = YES; } [ZLPhotoManager markSelcectModelInArr:self.albumListModel.models selArr:nav.arrSelectedModels]; @@ -130,9 +133,9 @@ - (void)viewDidLoad { [self setupCollectionView]; [self setupBottomView]; - ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; + ZLPhotoConfiguration *configuration = [(ZLImageNavigationController *)self.navigationController configuration]; - if (nav.allowSlideSelect) { + if (configuration.allowSlideSelect) { //添加滑动选择手势 UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)]; [self.view addGestureRecognizer:pan]; @@ -165,8 +168,8 @@ - (void)viewDidLayoutSubviews } BOOL showBottomView = YES; - ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; - if (nav.editAfterSelectThumbnailImage && nav.maxSelectCount == 1 && (nav.allowEditImage || nav.allowEditVideo)) { + ZLPhotoConfiguration *configuration = [(ZLImageNavigationController *)self.navigationController configuration]; + if (configuration.editAfterSelectThumbnailImage && configuration.maxSelectCount == 1 && (configuration.allowEditImage || configuration.allowEditVideo)) { //点击后直接编辑则不需要下方工具条 showBottomView = NO; inset.bottom = 0; @@ -184,14 +187,14 @@ - (void)viewDidLayoutSubviews self.bline.frame = CGRectMake(0, 0, width, 1/[UIScreen mainScreen].scale); CGFloat offsetX = 12; - if (nav.allowEditImage || nav.allowEditVideo) { + if (configuration.allowEditImage || configuration.allowEditVideo) { self.btnEdit.frame = CGRectMake(offsetX, 7, GetMatchValue(GetLocalLanguageTextValue(ZLPhotoBrowserEditText), 15, YES, bottomBtnH), bottomBtnH); offsetX = CGRectGetMaxX(self.btnEdit.frame) + 10; } self.btnPreView.frame = CGRectMake(offsetX, 7, GetMatchValue(GetLocalLanguageTextValue(ZLPhotoBrowserPreviewText), 15, YES, bottomBtnH), bottomBtnH); offsetX = CGRectGetMaxX(self.btnPreView.frame) + 10; - if (nav.allowSelectOriginal) { + if (configuration.allowSelectOriginal) { self.btnOriginalPhoto.frame = CGRectMake(offsetX, 7, GetMatchValue(GetLocalLanguageTextValue(ZLPhotoBrowserOriginalText), 15, YES, bottomBtnH)+self.btnOriginalPhoto.imageView.frame.size.width, bottomBtnH); offsetX = CGRectGetMaxX(self.btnOriginalPhoto.frame) + 5; @@ -229,8 +232,8 @@ - (BOOL)forceTouchAvailable - (void)scrollToBottom { - ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; - if (!nav.sortAscending) { + ZLPhotoConfiguration *configuration = [(ZLImageNavigationController *)self.navigationController configuration]; + if (!configuration.sortAscending) { return; } if (self.arrDataSources.count > 0) { @@ -245,6 +248,8 @@ - (void)scrollToBottom - (void)resetBottomBtnsStatus:(BOOL)getBytes { ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; + ZLPhotoConfiguration *configuration = nav.configuration; + if (nav.arrSelectedModels.count > 0) { self.btnOriginalPhoto.enabled = YES; self.btnPreView.enabled = YES; @@ -256,10 +261,9 @@ - (void)resetBottomBtnsStatus:(BOOL)getBytes } self.btnOriginalPhoto.selected = nav.isSelectOriginalPhoto; [self.btnDone setTitle:[NSString stringWithFormat:@"%@(%ld)", GetLocalLanguageTextValue(ZLPhotoBrowserDoneText), nav.arrSelectedModels.count] forState:UIControlStateNormal]; - [self.btnOriginalPhoto setTitleColor:nav.bottomBtnsNormalTitleColor forState:UIControlStateNormal]; - [self.btnPreView setTitleColor:nav.bottomBtnsNormalTitleColor forState:UIControlStateNormal]; - self.btnDone.backgroundColor = nav.bottomBtnsNormalTitleColor; - [self.btnDone setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; + [self.btnOriginalPhoto setTitleColor:configuration.bottomBtnsNormalTitleColor forState:UIControlStateNormal]; + [self.btnPreView setTitleColor:configuration.bottomBtnsNormalTitleColor forState:UIControlStateNormal]; + self.btnDone.backgroundColor = configuration.bottomBtnsNormalTitleColor; } else { self.btnOriginalPhoto.selected = NO; self.btnOriginalPhoto.enabled = NO; @@ -267,21 +271,20 @@ - (void)resetBottomBtnsStatus:(BOOL)getBytes self.btnDone.enabled = NO; self.labPhotosBytes.text = nil; [self.btnDone setTitle:GetLocalLanguageTextValue(ZLPhotoBrowserDoneText) forState:UIControlStateDisabled]; - [self.btnOriginalPhoto setTitleColor:nav.bottomBtnsDisableBgColor forState:UIControlStateDisabled]; - [self.btnPreView setTitleColor:nav.bottomBtnsDisableBgColor forState:UIControlStateDisabled]; - self.btnDone.backgroundColor = nav.bottomBtnsDisableBgColor; - [self.btnDone setTitleColor:[UIColor whiteColor] forState:UIControlStateDisabled]; + [self.btnOriginalPhoto setTitleColor:configuration.bottomBtnsDisableBgColor forState:UIControlStateDisabled]; + [self.btnPreView setTitleColor:configuration.bottomBtnsDisableBgColor forState:UIControlStateDisabled]; + self.btnDone.backgroundColor = configuration.bottomBtnsDisableBgColor; } BOOL canEdit = NO; if (nav.arrSelectedModels.count == 1) { ZLPhotoModel *m = nav.arrSelectedModels.firstObject; - canEdit = (nav.allowEditImage && ((m.type == ZLAssetMediaTypeImage) || - (m.type == ZLAssetMediaTypeGif && !nav.allowSelectGif) || - (m.type == ZLAssetMediaTypeLivePhoto && !nav.allowSelectLivePhoto))) || - (nav.allowEditVideo && m.type == ZLAssetMediaTypeVideo && round(m.asset.duration) >= nav.maxEditVideoTime); + canEdit = (configuration.allowEditImage && ((m.type == ZLAssetMediaTypeImage) || + (m.type == ZLAssetMediaTypeGif && !configuration.allowSelectGif) || + (m.type == ZLAssetMediaTypeLivePhoto && !configuration.allowSelectLivePhoto))) || + (configuration.allowEditVideo && m.type == ZLAssetMediaTypeVideo && round(m.asset.duration) >= configuration.maxEditVideoTime); } - [self.btnEdit setTitleColor:canEdit?nav.bottomBtnsNormalTitleColor:nav.bottomBtnsDisableBgColor forState:UIControlStateNormal]; + [self.btnEdit setTitleColor:canEdit?configuration.bottomBtnsNormalTitleColor:configuration.bottomBtnsDisableBgColor forState:UIControlStateNormal]; self.btnEdit.userInteractionEnabled = canEdit; } @@ -317,30 +320,30 @@ - (void)setupCollectionView [self.collectionView registerClass:NSClassFromString(@"ZLTakePhotoCell") forCellWithReuseIdentifier:@"ZLTakePhotoCell"]; [self.collectionView registerClass:NSClassFromString(@"ZLCollectionCell") forCellWithReuseIdentifier:@"ZLCollectionCell"]; //注册3d touch - ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; - if (nav.allowForceTouch && [self forceTouchAvailable]) { + ZLPhotoConfiguration *configuration = [(ZLImageNavigationController *)self.navigationController configuration]; + if (configuration.allowForceTouch && [self forceTouchAvailable]) { [self registerForPreviewingWithDelegate:self sourceView:self.collectionView]; } } - (void)setupBottomView { - ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; + ZLPhotoConfiguration *configuration = [(ZLImageNavigationController *)self.navigationController configuration]; - if (nav.editAfterSelectThumbnailImage && nav.maxSelectCount == 1 && (nav.allowEditImage || nav.allowEditVideo)) { + if (configuration.editAfterSelectThumbnailImage && configuration.maxSelectCount == 1 && (configuration.allowEditImage || configuration.allowEditVideo)) { //点击后直接编辑则不需要下方工具条 return; } self.bottomView = [[UIView alloc] init]; - self.bottomView.backgroundColor = nav.bottomViewBgColor; + self.bottomView.backgroundColor = configuration.bottomViewBgColor; [self.view addSubview:self.bottomView]; self.bline = [[UIView alloc] init]; self.bline.backgroundColor = kRGB(232, 232, 232); [self.bottomView addSubview:self.bline]; - if (nav.allowEditImage || nav.allowEditVideo) { + if (configuration.allowEditImage || configuration.allowEditVideo) { self.btnEdit = [UIButton buttonWithType:UIButtonTypeCustom]; self.btnEdit.titleLabel.font = [UIFont systemFontOfSize:15]; [self.btnEdit setTitle:GetLocalLanguageTextValue(ZLPhotoBrowserEditText) forState:UIControlStateNormal]; @@ -354,7 +357,7 @@ - (void)setupBottomView [self.btnPreView addTarget:self action:@selector(btnPreview_Click:) forControlEvents:UIControlEventTouchUpInside]; [self.bottomView addSubview:self.btnPreView]; - if (nav.allowSelectOriginal) { + if (configuration.allowSelectOriginal) { self.btnOriginalPhoto = [UIButton buttonWithType:UIButtonTypeCustom]; self.btnOriginalPhoto.titleLabel.font = [UIFont systemFontOfSize:15]; [self.btnOriginalPhoto setImage:GetImageWithName(@"btn_original_circle") forState:UIControlStateNormal]; @@ -365,12 +368,13 @@ - (void)setupBottomView self.labPhotosBytes = [[UILabel alloc] init]; self.labPhotosBytes.font = [UIFont systemFontOfSize:15]; - self.labPhotosBytes.textColor = nav.bottomBtnsNormalTitleColor; + self.labPhotosBytes.textColor = configuration.bottomBtnsNormalTitleColor; [self.bottomView addSubview:self.labPhotosBytes]; } self.btnDone = [UIButton buttonWithType:UIButtonTypeCustom]; self.btnDone.titleLabel.font = [UIFont systemFontOfSize:15]; + [self.btnDone setTitleColor:[UIColor whiteColor] forState:UIControlStateDisabled]; [self.btnDone setTitle:GetLocalLanguageTextValue(ZLPhotoBrowserDoneText) forState:UIControlStateNormal]; self.btnDone.layer.masksToBounds = YES; self.btnDone.layer.cornerRadius = 3.0f; @@ -381,7 +385,7 @@ - (void)setupBottomView - (void)initNavBtn { ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; - + ZLPhotoConfiguration *configuration = nav.configuration; nav.viewControllers.firstObject.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:GetLocalLanguageTextValue(ZLPhotoBrowserBackText) style:UIBarButtonItemStylePlain target:nil action:nil]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; @@ -389,7 +393,7 @@ - (void)initNavBtn btn.frame = CGRectMake(0, 0, width, 44); btn.titleLabel.font = [UIFont systemFontOfSize:16]; [btn setTitle:GetLocalLanguageTextValue(ZLPhotoBrowserCancelText) forState:UIControlStateNormal]; - [btn setTitleColor:nav.navTitleColor forState:UIControlStateNormal]; + [btn setTitleColor:configuration.navTitleColor forState:UIControlStateNormal]; [btn addTarget:self action:@selector(navRightBtn_Click) forControlEvents:UIControlEventTouchUpInside]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn]; } @@ -473,9 +477,11 @@ - (void)panAction:(UIPanGestureRecognizer *)pan CGPoint point = [pan locationInView:self.collectionView]; NSIndexPath *indexPath = [self.collectionView indexPathForItemAtPoint:point]; UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath]; + ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; + ZLPhotoConfiguration *configuration = nav.configuration; - BOOL asc = !self.allowTakePhoto || nav.sortAscending; + BOOL asc = !self.allowTakePhoto || configuration.sortAscending; if (pan.state == UIGestureRecognizerStateBegan) { _beginSelect = !indexPath ? NO : ![cell isKindOfClass:ZLTakePhotoCell.class]; @@ -488,9 +494,9 @@ - (void)panAction:(UIPanGestureRecognizer *)pan _beginSlideIndexPath = indexPath; if (!m.isSelected && [self canAddModel:m]) { - if (nav.editAfterSelectThumbnailImage && - nav.maxSelectCount == 1 && - (nav.allowEditImage || nav.allowEditVideo)) { + if (configuration.editAfterSelectThumbnailImage && + configuration.maxSelectCount == 1 && + (configuration.allowEditImage || configuration.allowEditVideo)) { [self shouldDirectEdit:m]; _selectType = SlideSelectTypeNone; return; @@ -509,7 +515,7 @@ - (void)panAction:(UIPanGestureRecognizer *)pan } ZLCollectionCell *c = (ZLCollectionCell *)cell; c.btnSelect.selected = m.isSelected; - c.topView.hidden = nav.showSelectedMask ? !m.isSelected : YES; + c.topView.hidden = configuration.showSelectedMask ? !m.isSelected : YES; [self resetBottomBtnsStatus:NO]; } } else if (pan.state == UIGestureRecognizerStateChanged) { @@ -587,7 +593,7 @@ - (void)panAction:(UIPanGestureRecognizer *)pan ZLCollectionCell *c = (ZLCollectionCell *)[self.collectionView cellForItemAtIndexPath:path]; c.btnSelect.selected = m.isSelected; - c.topView.hidden = nav.showSelectedMask ? !m.isSelected : YES; + c.topView.hidden = configuration.showSelectedMask ? !m.isSelected : YES; [self resetBottomBtnsStatus:NO]; } @@ -604,13 +610,15 @@ - (void)panAction:(UIPanGestureRecognizer *)pan - (BOOL)canAddModel:(ZLPhotoModel *)model { ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; - if (nav.arrSelectedModels.count >= nav.maxSelectCount) { - ShowToastLong(GetLocalLanguageTextValue(ZLPhotoBrowserMaxSelectCountText), nav.maxSelectCount); + ZLPhotoConfiguration *configuration =nav.configuration; + + if (nav.arrSelectedModels.count >= configuration.maxSelectCount) { + ShowToastLong(GetLocalLanguageTextValue(ZLPhotoBrowserMaxSelectCountText), configuration.maxSelectCount); return NO; } if (nav.arrSelectedModels.count > 0) { ZLPhotoModel *sm = nav.arrSelectedModels.firstObject; - if (!nav.allowMixSelect && + if (!configuration.allowMixSelect && ((model.type < ZLAssetMediaTypeVideo && sm.type == ZLAssetMediaTypeVideo) || (model.type == ZLAssetMediaTypeVideo && sm.type < ZLAssetMediaTypeVideo))) { ShowToastLong(@"%@", GetLocalLanguageTextValue(ZLPhotoBrowserCannotSelectVideo)); return NO; @@ -620,8 +628,8 @@ - (BOOL)canAddModel:(ZLPhotoModel *)model ShowToastLong(@"%@", GetLocalLanguageTextValue(ZLPhotoBrowseriCloudPhotoText)); return NO; } - if (model.type == ZLAssetMediaTypeVideo && GetDuration(model.duration) > nav.maxVideoDuration) { - ShowToastLong(GetLocalLanguageTextValue(ZLPhotoBrowserMaxVideoDurationText), nav.maxVideoDuration); + if (model.type == ZLAssetMediaTypeVideo && GetDuration(model.duration) > configuration.maxVideoDuration) { + ShowToastLong(GetLocalLanguageTextValue(ZLPhotoBrowserMaxVideoDurationText), configuration.maxVideoDuration); return NO; } return YES; @@ -643,13 +651,13 @@ - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSe - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { - ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; + ZLPhotoConfiguration *configuration = [(ZLImageNavigationController *)self.navigationController configuration]; - if (self.allowTakePhoto && ((nav.sortAscending && indexPath.row >= self.arrDataSources.count) || (!nav.sortAscending && indexPath.row == 0))) { + if (self.allowTakePhoto && ((configuration.sortAscending && indexPath.row >= self.arrDataSources.count) || (!configuration.sortAscending && indexPath.row == 0))) { ZLTakePhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ZLTakePhotoCell" forIndexPath:indexPath]; cell.layer.masksToBounds = YES; - cell.layer.cornerRadius = nav.cellCornerRadio; - if (nav.showCaptureImageOnTakePhotoBtn) { + cell.layer.cornerRadius = configuration.cellCornerRadio; + if (configuration.showCaptureImageOnTakePhotoBtn) { [cell startCapture]; } return cell; @@ -658,7 +666,7 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell ZLCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ZLCollectionCell" forIndexPath:indexPath]; ZLPhotoModel *model; - if (!self.allowTakePhoto || nav.sortAscending) { + if (!self.allowTakePhoto || configuration.sortAscending) { model = self.arrDataSources[indexPath.row]; } else { model = self.arrDataSources[indexPath.row-1]; @@ -692,19 +700,18 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell } } } - - if (weakNav.showSelectedMask) { + if (configuration.showSelectedMask) { strongCell.topView.hidden = !model.isSelected; } [strongSelf resetBottomBtnsStatus:YES]; }; - cell.allSelectGif = nav.allowSelectGif; - cell.allSelectLivePhoto = nav.allowSelectLivePhoto; - cell.showSelectBtn = nav.showSelectBtn; - cell.cornerRadio = nav.cellCornerRadio; - cell.showMask = nav.showSelectedMask; - cell.maskColor = nav.selectedMaskColor; + cell.allSelectGif = configuration.allowSelectGif; + cell.allSelectLivePhoto = configuration.allowSelectLivePhoto; + cell.showSelectBtn = configuration.showSelectBtn; + cell.cornerRadio = configuration.cellCornerRadio; + cell.showMask = configuration.showSelectedMask; + cell.maskColor = configuration.selectedMaskColor; cell.model = model; return cell; @@ -713,15 +720,16 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell #pragma mark - UICollectionViewDelegate - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { - ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; - if (self.allowTakePhoto && ((nav.sortAscending && indexPath.row >= self.arrDataSources.count) || (!nav.sortAscending && indexPath.row == 0))) { + ZLPhotoConfiguration *configuration = [(ZLImageNavigationController *)self.navigationController configuration]; + + if (self.allowTakePhoto && ((configuration.sortAscending && indexPath.row >= self.arrDataSources.count) || (!configuration.sortAscending && indexPath.row == 0))) { //拍照 [self takePhoto]; return; } NSInteger index = indexPath.row; - if (self.allowTakePhoto && !nav.sortAscending) { + if (self.allowTakePhoto && !configuration.sortAscending) { index = indexPath.row - 1; } ZLPhotoModel *model = self.arrDataSources[index]; @@ -737,10 +745,11 @@ - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPa - (BOOL)shouldDirectEdit:(ZLPhotoModel *)model { ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; + ZLPhotoConfiguration *configuration = nav.configuration; //当前点击图片可编辑 - BOOL editImage = nav.editAfterSelectThumbnailImage && nav.allowEditImage && nav.maxSelectCount == 1 && (model.type == ZLAssetMediaTypeImage || model.type == ZLAssetMediaTypeGif || model.type == ZLAssetMediaTypeLivePhoto); + BOOL editImage = configuration.editAfterSelectThumbnailImage && configuration.allowEditImage && configuration.maxSelectCount == 1 && (model.type == ZLAssetMediaTypeImage || model.type == ZLAssetMediaTypeGif || model.type == ZLAssetMediaTypeLivePhoto); //当前点击视频可编辑 - BOOL editVideo = nav.editAfterSelectThumbnailImage && nav.allowEditVideo && model.type == ZLAssetMediaTypeVideo && nav.maxSelectCount == 1 && round(model.asset.duration) >= nav.maxEditVideoTime; + BOOL editVideo = configuration.editAfterSelectThumbnailImage && configuration.allowEditVideo && model.type == ZLAssetMediaTypeVideo && configuration.maxSelectCount == 1 && round(model.asset.duration) >= configuration.maxEditVideoTime; //当前未选择图片 或 已经选择了一张并且点击的是已选择的图片 BOOL flag = nav.arrSelectedModels.count == 0 || (nav.arrSelectedModels.count == 1 && [nav.arrSelectedModels.firstObject.asset.localIdentifier isEqualToString:model.asset.localIdentifier]); @@ -752,7 +761,7 @@ - (BOOL)shouldDirectEdit:(ZLPhotoModel *)model [self btnEdit_Click:nil]; } - return nav.editAfterSelectThumbnailImage && nav.maxSelectCount == 1 && (nav.allowEditImage || nav.allowEditVideo); + return configuration.editAfterSelectThumbnailImage && configuration.maxSelectCount == 1 && (configuration.allowEditImage || configuration.allowEditVideo); } /** @@ -761,20 +770,21 @@ - (BOOL)shouldDirectEdit:(ZLPhotoModel *)model - (UIViewController *)getMatchVCWithModel:(ZLPhotoModel *)model { ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; + ZLPhotoConfiguration *configuration = nav.configuration; if (nav.arrSelectedModels.count > 0) { ZLPhotoModel *sm = nav.arrSelectedModels.firstObject; - if (!nav.allowMixSelect && + if (!configuration.allowMixSelect && ((model.type < ZLAssetMediaTypeVideo && sm.type == ZLAssetMediaTypeVideo) || (model.type == ZLAssetMediaTypeVideo && sm.type < ZLAssetMediaTypeVideo))) { ShowToastLong(@"%@", GetLocalLanguageTextValue(ZLPhotoBrowserCannotSelectVideo)); return nil; } } - BOOL allowSelImage = !(model.type==ZLAssetMediaTypeVideo)?YES:nav.allowMixSelect; - BOOL allowSelVideo = model.type==ZLAssetMediaTypeVideo?YES:nav.allowMixSelect; + BOOL allowSelImage = !(model.type==ZLAssetMediaTypeVideo)?YES:configuration.allowMixSelect; + BOOL allowSelVideo = model.type==ZLAssetMediaTypeVideo?YES:configuration.allowMixSelect; - NSArray *arr = [ZLPhotoManager getPhotoInResult:self.albumListModel.result allowSelectVideo:allowSelVideo allowSelectImage:allowSelImage allowSelectGif:nav.allowSelectGif allowSelectLivePhoto:nav.allowSelectLivePhoto]; + NSArray *arr = [ZLPhotoManager getPhotoInResult:self.albumListModel.result allowSelectVideo:allowSelVideo allowSelectImage:allowSelImage allowSelectGif:configuration.allowSelectGif allowSelectLivePhoto:configuration.allowSelectLivePhoto]; NSMutableArray *selIdentifiers = [NSMutableArray array]; for (ZLPhotoModel *m in nav.arrSelectedModels) { @@ -800,14 +810,14 @@ - (UIViewController *)getMatchVCWithModel:(ZLPhotoModel *)model - (void)takePhoto { - ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; + ZLPhotoConfiguration *configuration = [(ZLImageNavigationController *)self.navigationController configuration]; if (![ZLPhotoManager haveCameraAuthority]) { NSString *message = [NSString stringWithFormat:GetLocalLanguageTextValue(ZLPhotoBrowserNoCameraAuthorityText), kAPPName]; ShowAlert(message, self); return; } - if (nav.useSystemCamera) { + if (configuration.useSystemCamera) { //系统相机拍照 if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]){ @@ -825,10 +835,10 @@ - (void)takePhoto return; } ZLCustomCamera *camera = [[ZLCustomCamera alloc] init]; - camera.allowRecordVideo = nav.allowRecordVideo; - camera.sessionPreset = nav.sessionPreset; - camera.circleProgressColor = nav.bottomBtnsNormalTitleColor; - camera.maxRecordDuration = nav.maxRecordDuration; + camera.allowRecordVideo = configuration.allowRecordVideo; + camera.sessionPreset = configuration.sessionPreset; + camera.circleProgressColor = configuration.bottomBtnsNormalTitleColor; + camera.maxRecordDuration = configuration.maxRecordDuration; zl_weakify(self); camera.doneBlock = ^(UIImage *image, NSURL *videoUrl) { zl_strongify(weakSelf); @@ -885,16 +895,18 @@ - (void)saveImage:(UIImage *)image videoUrl:(NSURL *)videoUrl - (void)handleDataArray:(ZLPhotoModel *)model { ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; - if (nav.sortAscending) { + ZLPhotoConfiguration *configuration = nav.configuration; + + if (configuration.sortAscending) { [self.arrDataSources addObject:model]; } else { [self.arrDataSources insertObject:model atIndex:0]; } - if (nav.maxSelectCount > 1 && nav.arrSelectedModels.count < nav.maxSelectCount) { + if (configuration.maxSelectCount > 1 && nav.arrSelectedModels.count < configuration.maxSelectCount) { model.selected = YES; [nav.arrSelectedModels addObject:model]; - self.albumListModel = [ZLPhotoManager getCameraRollAlbumList:nav.allowSelectVideo allowSelectImage:nav.allowSelectImage]; - } else if (nav.maxSelectCount == 1 && !nav.arrSelectedModels.count) { + self.albumListModel = [ZLPhotoManager getCameraRollAlbumList:configuration.allowSelectVideo allowSelectImage:configuration.allowSelectImage]; + } else if (configuration.maxSelectCount == 1 && !nav.arrSelectedModels.count) { if (![self shouldDirectEdit:model]) { model.selected = YES; [nav.arrSelectedModels addObject:model]; @@ -942,15 +954,16 @@ - (UIViewController *)previewingContext:(id)previewi ZLForceTouchPreviewController *vc = [[ZLForceTouchPreviewController alloc] init]; - ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController; + ZLPhotoConfiguration *configuration = [(ZLImageNavigationController *)self.navigationController configuration]; + NSInteger index = indexPath.row; - if (self.allowTakePhoto && !nav.sortAscending) { + if (self.allowTakePhoto && !configuration.sortAscending) { index = indexPath.row - 1; } ZLPhotoModel *model = self.arrDataSources[index]; vc.model = model; - vc.allowSelectGif = nav.allowSelectGif; - vc.allowSelectLivePhoto = nav.allowSelectLivePhoto; + vc.allowSelectGif = configuration.allowSelectGif; + vc.allowSelectLivePhoto = configuration.allowSelectLivePhoto; vc.preferredContentSize = [self getSize:model]; diff --git a/README.md b/README.md index cbdb9343..838d687a 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ ### 更新日志 ``` +● 2.5.2: 提取相册配置参数独立为'ZLPhotoConfiguration'对象; 新增状态栏样式api; 优化部分代码; ● 2.5.1: ①:新增自定义相机(仿微信),开发者可选使用自定义相机或系统相机; ②:支持录制视频,可设置最大录制时长及清晰度; ● 2.5.0.2: 新增自行切换框架语言api; 编辑图片界面当只有一个比例且为custom或1:1状态下隐藏比例切换工具条; @@ -62,8 +63,6 @@ ● 2.2.6: ①:可混合选择image、gif、livephoto、video类型; ②:支持video、gif、livephoto类型的多选; ③:支持控制video最大选择时长; -● 2.2.3: 新增图片编辑功能; -● 2.2.1: 新增3D Touch预览功能 (需设备支持); ``` ### 框架支持 @@ -106,22 +105,25 @@ Privacy - Microphone Usage Description ```objc #import "ZLPhotoActionSheet.h" -ZLPhotoActionSheet *actionSheet = [[ZLPhotoActionSheet alloc] init]; -//设置照片最大预览数 -actionSheet.maxPreviewCount = 20; -//设置照片最大选择数 -actionSheet.maxSelectCount = 10; -actionSheet.sender = self; - -[actionSheet setSelectImageBlock:^(NSArray * _Nonnull images, NSArray * _Nonnull assets, BOOL isOriginal) { +ZLPhotoActionSheet *ac = [[ZLPhotoActionSheet alloc] init]; + +//相册参数配置 +ZLPhotoConfiguration *configuration = [ZLPhotoConfiguration defaultPhotoConfiguration]; +ac.configuration = configuration; + +//如调用的方法无sender参数,则该参数必传 +ac.sender = self; + +//选择回调 +[ac setSelectImageBlock:^(NSArray * _Nonnull images, NSArray * _Nonnull assets, BOOL isOriginal) { //your codes }]; //调用相册 -[actionSheet showPreviewAnimated:YES]; +[ac showPreviewAnimated:YES]; //预览网络图片 -[actionSheet previewPhotos:arrNetImages index:0 hideToolBar:YES complete:^(NSArray * _Nonnull photos) { +[ac previewPhotos:arrNetImages index:0 hideToolBar:YES complete:^(NSArray * _Nonnull photos) { //your codes }]; ``` diff --git a/ZLPhotoBrowser.podspec b/ZLPhotoBrowser.podspec index 81d425c4..fdaafe1d 100644 --- a/ZLPhotoBrowser.podspec +++ b/ZLPhotoBrowser.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'ZLPhotoBrowser' - s.version = '2.5.1.1' + s.version = '2.5.2' s.summary = 'A simple way to multiselect photos from ablum, force touch to preview photo, support portrait and landscape, edit photo, multiple languages(Chinese,English,Japanese)' s.homepage = 'https://github.com/longitachi/ZLPhotoBrowser' s.license = 'MIT' diff --git a/ZLPhotoBrowser.xcodeproj/project.pbxproj b/ZLPhotoBrowser.xcodeproj/project.pbxproj index e2f12247..85e449cc 100644 --- a/ZLPhotoBrowser.xcodeproj/project.pbxproj +++ b/ZLPhotoBrowser.xcodeproj/project.pbxproj @@ -32,6 +32,7 @@ FD22D71F1E9E25D1008FCC4E /* ZLPhotoModel.m in Sources */ = {isa = PBXBuildFile; fileRef = FD22D71E1E9E25D1008FCC4E /* ZLPhotoModel.m */; }; FD22D7221E9E2EDC008FCC4E /* ZLPhotoManager.m in Sources */ = {isa = PBXBuildFile; fileRef = FD22D7211E9E2EDC008FCC4E /* ZLPhotoManager.m */; }; FD3771191DB8C04B00CAD645 /* NSBundle+ZLPhotoBrowser.m in Sources */ = {isa = PBXBuildFile; fileRef = FD3771181DB8C04B00CAD645 /* NSBundle+ZLPhotoBrowser.m */; }; + FD7003DF1FBD2EAB000D9FD4 /* ZLPhotoConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = FD7003DE1FBD2EAB000D9FD4 /* ZLPhotoConfiguration.m */; }; FD7852511EF4FD5300C69E84 /* PhotosUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FD7852501EF4FD5300C69E84 /* PhotosUI.framework */; }; FD7B52731EFCB81600FB9087 /* ZLEditViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = FD7B52721EFCB81600FB9087 /* ZLEditViewController.m */; }; FD92FA6D1F32B4CE00D7B8C1 /* UIButton+EnlargeTouchArea.m in Sources */ = {isa = PBXBuildFile; fileRef = FD92FA6C1F32B4CE00D7B8C1 /* UIButton+EnlargeTouchArea.m */; }; @@ -90,6 +91,8 @@ FD22D7211E9E2EDC008FCC4E /* ZLPhotoManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ZLPhotoManager.m; sourceTree = ""; }; FD3771171DB8C04B00CAD645 /* NSBundle+ZLPhotoBrowser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSBundle+ZLPhotoBrowser.h"; sourceTree = ""; }; FD3771181DB8C04B00CAD645 /* NSBundle+ZLPhotoBrowser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSBundle+ZLPhotoBrowser.m"; sourceTree = ""; }; + FD7003DD1FBD2EAB000D9FD4 /* ZLPhotoConfiguration.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ZLPhotoConfiguration.h; sourceTree = ""; }; + FD7003DE1FBD2EAB000D9FD4 /* ZLPhotoConfiguration.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ZLPhotoConfiguration.m; sourceTree = ""; }; FD7852501EF4FD5300C69E84 /* PhotosUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = PhotosUI.framework; path = System/Library/Frameworks/PhotosUI.framework; sourceTree = SDKROOT; }; FD7B52711EFCB81600FB9087 /* ZLEditViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ZLEditViewController.h; sourceTree = ""; }; FD7B52721EFCB81600FB9087 /* ZLEditViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ZLEditViewController.m; sourceTree = ""; }; @@ -143,6 +146,8 @@ FD10CECF1EA882490041095C /* ZLCollectionCell.h */, FD10CECD1EA86AF60041095C /* ZLCollectionCell.m */, FD028BAC1CBE33BB009DD2FC /* ZLDefine.h */, + FD7003DD1FBD2EAB000D9FD4 /* ZLPhotoConfiguration.h */, + FD7003DE1FBD2EAB000D9FD4 /* ZLPhotoConfiguration.m */, FD028BAF1CBE33BB009DD2FC /* ZLPhotoActionSheet.h */, FD028BB01CBE33BB009DD2FC /* ZLPhotoActionSheet.m */, FD028BB11CBE33BB009DD2FC /* ZLPhotoBrowser.h */, @@ -383,6 +388,7 @@ buildActionMask = 2147483647; files = ( FDD979E61EF8F35700DD9DA4 /* ZLForceTouchPreviewController.m in Sources */, + FD7003DF1FBD2EAB000D9FD4 /* ZLPhotoConfiguration.m in Sources */, FD028BD31CBE33BB009DD2FC /* ToastUtils.m in Sources */, FD028BD51CBE33BB009DD2FC /* ZLBigImageCell.m in Sources */, FD0787281C0D45A200D17B97 /* ViewController.m in Sources */, @@ -537,7 +543,7 @@ INFOPLIST_FILE = ZLPhotoBrowser/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = ZL.ABC; + PRODUCT_BUNDLE_IDENTIFIER = ZL.ABCD; PRODUCT_NAME = "$(TARGET_NAME)"; TARGETED_DEVICE_FAMILY = 1; }; @@ -552,7 +558,7 @@ INFOPLIST_FILE = ZLPhotoBrowser/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = ZL.ABC; + PRODUCT_BUNDLE_IDENTIFIER = ZL.ABCD; PRODUCT_NAME = "$(TARGET_NAME)"; TARGETED_DEVICE_FAMILY = 1; }; diff --git a/ZLPhotoBrowser/Base.lproj/Main.storyboard b/ZLPhotoBrowser/Base.lproj/Main.storyboard index 3c0fcd0b..4f07c1c2 100644 --- a/ZLPhotoBrowser/Base.lproj/Main.storyboard +++ b/ZLPhotoBrowser/Base.lproj/Main.storyboard @@ -1,11 +1,11 @@ - + - + @@ -141,7 +141,7 @@ - + diff --git a/ZLPhotoBrowser/ViewController.m b/ZLPhotoBrowser/ViewController.m index b265714c..94d56758 100644 --- a/ZLPhotoBrowser/ViewController.m +++ b/ZLPhotoBrowser/ViewController.m @@ -15,6 +15,7 @@ #import "ZLPhotoModel.h" #import "ZLPhotoManager.h" #import "ZLProgressHUD.h" +#import "ZLPhotoConfiguration.h" /////////////////////////////////////////////////// // git 地址: https://github.com/longitachi/ZLPhotoBrowser @@ -91,50 +92,61 @@ - (ZLPhotoActionSheet *)getPas { ZLPhotoActionSheet *actionSheet = [[ZLPhotoActionSheet alloc] init]; -#pragma mark - optional +#pragma mark - 参数配置 optional,可直接使用 defaultPhotoConfiguration + ZLPhotoConfiguration *configuration = [ZLPhotoConfiguration defaultPhotoConfiguration]; //以下参数为自定义参数,均可不设置,有默认值 - actionSheet.sortAscending = self.sortSegment.selectedSegmentIndex==0; - actionSheet.allowSelectImage = self.selImageSwitch.isOn; - actionSheet.allowSelectGif = self.selGifSwitch.isOn; - actionSheet.allowSelectVideo = self.selVideoSwitch.isOn; - actionSheet.allowSelectLivePhoto = self.selLivePhotoSwitch.isOn; - actionSheet.allowForceTouch = self.allowForceTouchSwitch.isOn; - actionSheet.allowEditImage = self.allowEditSwitch.isOn; - actionSheet.allowEditVideo = self.allowEditVideoSwitch.isOn; - actionSheet.allowSlideSelect = self.allowSlideSelectSwitch.isOn; - actionSheet.allowMixSelect = self.mixSelectSwitch.isOn; - actionSheet.allowDragSelect = self.allowDragSelectSwitch.isOn; + configuration.sortAscending = self.sortSegment.selectedSegmentIndex==0; + configuration.allowSelectImage = self.selImageSwitch.isOn; + configuration.allowSelectGif = self.selGifSwitch.isOn; + configuration.allowSelectVideo = self.selVideoSwitch.isOn; + configuration.allowSelectLivePhoto = self.selLivePhotoSwitch.isOn; + configuration.allowForceTouch = self.allowForceTouchSwitch.isOn; + configuration.allowEditImage = self.allowEditSwitch.isOn; + configuration.allowEditVideo = self.allowEditVideoSwitch.isOn; + configuration.allowSlideSelect = self.allowSlideSelectSwitch.isOn; + configuration.allowMixSelect = self.mixSelectSwitch.isOn; + configuration.allowDragSelect = self.allowDragSelectSwitch.isOn; //设置相册内部显示拍照按钮 - actionSheet.allowTakePhotoInLibrary = self.takePhotoInLibrarySwitch.isOn; + configuration.allowTakePhotoInLibrary = self.takePhotoInLibrarySwitch.isOn; //设置在内部拍照按钮上实时显示相机俘获画面 - actionSheet.showCaptureImageOnTakePhotoBtn = self.showCaptureImageSwitch.isOn; + configuration.showCaptureImageOnTakePhotoBtn = self.showCaptureImageSwitch.isOn; //设置照片最大预览数 - actionSheet.maxPreviewCount = self.previewTextField.text.integerValue; + configuration.maxPreviewCount = self.previewTextField.text.integerValue; //设置照片最大选择数 - actionSheet.maxSelectCount = self.maxSelCountTextField.text.integerValue; + configuration.maxSelectCount = self.maxSelCountTextField.text.integerValue; //设置允许选择的视频最大时长 - actionSheet.maxVideoDuration = self.maxVideoDurationTextField.text.integerValue; + configuration.maxVideoDuration = self.maxVideoDurationTextField.text.integerValue; //设置照片cell弧度 - actionSheet.cellCornerRadio = self.cornerRadioTextField.text.floatValue; + configuration.cellCornerRadio = self.cornerRadioTextField.text.floatValue; //单选模式是否显示选择按钮 -// actionSheet.showSelectBtn = YES; +// configuration.showSelectBtn = YES; //是否在选择图片后直接进入编辑界面 - actionSheet.editAfterSelectThumbnailImage = self.editAfterSelectImageSwitch.isOn; + configuration.editAfterSelectThumbnailImage = self.editAfterSelectImageSwitch.isOn; //设置编辑比例 -// actionSheet.clipRatios = @[GetClipRatio(1, 1)]; +// configuration.clipRatios = @[GetClipRatio(1, 1)]; //是否在已选择照片上显示遮罩层 - actionSheet.showSelectedMask = self.maskSwitch.isOn; - //遮罩层颜色 -// actionSheet.selectedMaskColor = [UIColor orangeColor]; - //允许框架解析图片 - actionSheet.shouldAnialysisAsset = self.allowAnialysisAssetSwitch.isOn; - actionSheet.languageType = self.languageSegment.selectedSegmentIndex; -// actionSheet.useSystemCamera = YES; -// actionSheet.sessionPreset = ZLCaptureSessionPreset1920x1080; + configuration.showSelectedMask = self.maskSwitch.isOn; + //颜色,状态栏样式 +// configuration.selectedMaskColor = [UIColor purpleColor]; +// configuration.navBarColor = [UIColor orangeColor]; +// configuration.navTitleColor = [UIColor blackColor]; +// configuration.bottomBtnsNormalTitleColor = kRGB(80, 160, 100); +// configuration.bottomBtnsDisableBgColor = kRGB(190, 30, 90); +// configuration.bottomViewBgColor = [UIColor blackColor]; +// configuration.statusBarStyle = UIStatusBarStyleDefault; + //是否允许框架解析图片 + configuration.shouldAnialysisAsset = self.allowAnialysisAssetSwitch.isOn; + //框架语言 + configuration.languageType = self.languageSegment.selectedSegmentIndex; + //是否使用系统相机 +// configuration.useSystemCamera = YES; +// configuration.sessionPreset = ZLCaptureSessionPreset1920x1080; + #pragma mark - required + actionSheet.configuration = configuration; //如果调用的方法没有传sender,则该属性必须提前赋值 actionSheet.sender = self; - + //记录上次选择的图片 actionSheet.arrSelectedAssets = self.rememberLastSelSwitch.isOn&&self.maxSelCountTextField.text.integerValue>1 ? self.lastSelectAssets : nil; zl_weakify(self);