Skip to content

Commit

Permalink
添加自定义导航返回图片功能 fix #264
Browse files Browse the repository at this point in the history
  • Loading branch information
longitachi committed Jun 20, 2018
1 parent 5376104 commit fb72d6c
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 11 deletions.
18 changes: 14 additions & 4 deletions PhotoBrowser/ZLPhotoActionSheet.m
Original file line number Diff line number Diff line change
Expand Up @@ -919,16 +919,26 @@ - (void)saveImage:(UIImage *)image videoUrl:(NSURL *)videoUrl

- (void)handleDataArray:(ZLPhotoModel *)model
{
zl_weakify(self);
BOOL (^shouldSelect)(void) = ^BOOL() {
zl_strongify(weakSelf);
if (model.type == ZLAssetMediaTypeVideo) {
return (model.asset.duration <= strongSelf.configuration.maxVideoDuration);
}
return YES;
};

[self.arrDataSources insertObject:model atIndex:0];
if (self.arrDataSources.count > self.configuration.maxPreviewCount) {
[self.arrDataSources removeLastObject];
}
if (self.configuration.maxSelectCount > 1 && self.arrSelectedModels.count < self.configuration.maxSelectCount) {
model.selected = YES;
BOOL sel = shouldSelect();
if (self.configuration.maxSelectCount > 1 && self.arrSelectedModels.count < self.configuration.maxSelectCount && sel) {
model.selected = sel;
[self.arrSelectedModels addObject:model];
} else if (self.configuration.maxSelectCount == 1 && !self.arrSelectedModels.count) {
} else if (self.configuration.maxSelectCount == 1 && !self.arrSelectedModels.count && sel) {
if (![self shouldDirectEdit:model]) {
model.selected = YES;
model.selected = sel;
[self.arrSelectedModels addObject:model];
[self requestSelPhotos:nil data:self.arrSelectedModels hideAfterCallBack:YES];
return;
Expand Down
2 changes: 2 additions & 0 deletions PhotoBrowser/ZLPhotoBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ - (void)setConfiguration:(ZLPhotoConfiguration *)configuration
[self.navigationBar setBackgroundImage:[self imageWithColor:configuration.navBarColor] forBarMetrics:UIBarMetricsDefault];
[self.navigationBar setTintColor:configuration.navTitleColor];
[self.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: configuration.navTitleColor}];
[self.navigationBar setBackIndicatorImage:GetImageWithName(@"zl_navBack")];
[self.navigationBar setBackIndicatorTransitionMaskImage:GetImageWithName(@"zl_navBack")];
}

- (UIImage *)imageWithColor:(UIColor *)color
Expand Down
2 changes: 1 addition & 1 deletion PhotoBrowser/ZLShowBigImgViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ - (void)initNavView
[self.view addSubview:_navView];

_btnBack = [UIButton buttonWithType:UIButtonTypeCustom];
[_btnBack setImage:GetImageWithName(@"zl_navBackBtn") forState:UIControlStateNormal];
[_btnBack setImage:GetImageWithName(@"zl_navBack") forState:UIControlStateNormal];
[_btnBack setImageEdgeInsets:UIEdgeInsetsMake(0, -10, 0, 0)];
[_btnBack addTarget:self action:@selector(btnBack_Click) forControlEvents:UIControlEventTouchUpInside];
[_navView addSubview:_btnBack];
Expand Down
20 changes: 15 additions & 5 deletions PhotoBrowser/ZLThumbnailViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -916,23 +916,33 @@ - (void)handleDataArray:(ZLPhotoModel *)model
ZLImageNavigationController *nav = (ZLImageNavigationController *)self.navigationController;
ZLPhotoConfiguration *configuration = nav.configuration;

BOOL (^shouldSelect)(void) = ^BOOL() {
if (model.type == ZLAssetMediaTypeVideo) {
return (model.asset.duration <= configuration.maxVideoDuration);
}
return YES;
};

if (configuration.sortAscending) {
[self.arrDataSources addObject:model];
} else {
[self.arrDataSources insertObject:model atIndex:0];
}
if (configuration.maxSelectCount > 1 && nav.arrSelectedModels.count < configuration.maxSelectCount) {
model.selected = YES;

BOOL sel = shouldSelect();
if (configuration.maxSelectCount > 1 && nav.arrSelectedModels.count < configuration.maxSelectCount && sel) {
model.selected = sel;
[nav.arrSelectedModels addObject:model];
self.albumListModel = [ZLPhotoManager getCameraRollAlbumList:configuration.allowSelectVideo allowSelectImage:configuration.allowSelectImage];
} else if (configuration.maxSelectCount == 1 && !nav.arrSelectedModels.count) {
} else if (configuration.maxSelectCount == 1 && !nav.arrSelectedModels.count && sel) {
if (![self shouldDirectEdit:model]) {
model.selected = YES;
model.selected = sel;
[nav.arrSelectedModels addObject:model];
[self btnDone_Click:nil];
return;
}
}

self.albumListModel = [ZLPhotoManager getCameraRollAlbumList:configuration.allowSelectVideo allowSelectImage:configuration.allowSelectImage];
[self.collectionView reloadData];
[self scrollToBottom];
[self resetBottomBtnsStatus:YES];
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
4 changes: 3 additions & 1 deletion ZLPhotoBrowser/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,15 @@ - (ZLPhotoActionSheet *)getPas
actionSheet.configuration.languageType = self.languageSegment.selectedSegmentIndex;
//自定义多语言
// actionSheet.configuration.customLanguageKeyValue = @{@"ZLPhotoBrowserCameraText": @"没错,我就是一个相机"};
//自定义图片
// actionSheet.configuration.customImageNames = @[@"zl_navBack"];

//是否使用系统相机
// actionSheet.configuration.useSystemCamera = YES;
// actionSheet.configuration.sessionPreset = ZLCaptureSessionPreset1920x1080;
// actionSheet.configuration.exportVideoType = ZLExportVideoTypeMp4;
// actionSheet.configuration.allowRecordVideo = NO;

// actionSheet.configuration.maxVideoDuration = 5;
#pragma mark - required
//如果调用的方法没有传sender,则该属性必须提前赋值
actionSheet.sender = self;
Expand Down

0 comments on commit fb72d6c

Please sign in to comment.