Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

新增初始化方法,可选择在照片选择页面快捷打开相册列表 #1585

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions TZImagePickerController/TZImagePickerController/TZAssetCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ typedef enum : NSUInteger {

@class TZAlbumModel;
@interface TZAlbumCell : UITableViewCell
@property (nonatomic, assign) BOOL showAlbumInPhotoPickerVc;
@property (nonatomic, strong) TZAlbumModel *model;
@property (nonatomic, assign) BOOL isSelected;

@property (weak, nonatomic) UIButton *selectedCountButton;

@property (nonatomic, copy) void (^albumCellDidSetModelBlock)(TZAlbumCell *cell, UIImageView *posterImageView, UILabel *titleLabel);
Expand Down
32 changes: 30 additions & 2 deletions TZImagePickerController/TZImagePickerController/TZAssetCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -396,20 +396,24 @@ - (void)dealloc {
@interface TZAlbumCell ()
@property (weak, nonatomic) UIImageView *posterImageView;
@property (weak, nonatomic) UILabel *titleLabel;
@property (weak, nonatomic) UIImageView *selectedImageView;
@end

@implementation TZAlbumCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
self.backgroundColor = [UIColor whiteColor];
self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return self;
}

- (void)setModel:(TZAlbumModel *)model {
_model = model;

if (self.showAlbumInPhotoPickerVc == NO) {
self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}

UIColor *nameColor = UIColor.blackColor;
if (@available(iOS 13.0, *)) {
nameColor = UIColor.labelColor;
Expand All @@ -434,9 +438,22 @@ - (void)setModel:(TZAlbumModel *)model {
}
}

- (void)setIsSelected:(BOOL)isSelected {
_isSelected = isSelected;

self.selectedImageView.hidden = !self.isSelected;
}

- (void)layoutSubviews {
[super layoutSubviews];
_selectedCountButton.frame = CGRectMake(self.contentView.tz_width - 24, 23, 24, 24);
if (self.showAlbumInPhotoPickerVc) {
CGSize size = self.selectedImageView.image.size;
self.selectedImageView.frame = CGRectMake(self.tz_width - 20 - size.width, (self.tz_height - size.height) / 2, size.width, size.height);
size = CGSizeMake(24, 24);
_selectedCountButton.frame = CGRectMake(self.selectedImageView.tz_left - 5 - size.width, (self.tz_height - size.height) / 2, size.width, size.height);
}else{
_selectedCountButton.frame = CGRectMake(self.contentView.tz_width - 24, 23, 24, 24);
}
NSInteger titleHeight = ceil(self.titleLabel.font.lineHeight);
self.titleLabel.frame = CGRectMake(80, (self.tz_height - titleHeight) / 2, self.tz_width - 80 - 50, titleHeight);
self.posterImageView.frame = CGRectMake(0, 0, 70, 70);
Expand Down Expand Up @@ -494,6 +511,17 @@ - (UIButton *)selectedCountButton {
return _selectedCountButton;
}

- (UIImageView *)selectedImageView {
if (_selectedImageView == nil) {
UIImageView *selectedImageView = [[UIImageView alloc] init];
[selectedImageView setHidden:YES];
selectedImageView.image = [UIImage tz_imageNamedFromMyBundle:@"photo_sel_photoPickerVc"];
[self.contentView addSubview:selectedImageView];
_selectedImageView = selectedImageView;
}
return _selectedImageView;
}

@end


Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
- (instancetype)initWithMaxImagesCount:(NSInteger)maxImagesCount delegate:(id<TZImagePickerControllerDelegate>)delegate;
- (instancetype)initWithMaxImagesCount:(NSInteger)maxImagesCount columnNumber:(NSInteger)columnNumber delegate:(id<TZImagePickerControllerDelegate>)delegate;
- (instancetype)initWithMaxImagesCount:(NSInteger)maxImagesCount columnNumber:(NSInteger)columnNumber delegate:(id<TZImagePickerControllerDelegate>)delegate pushPhotoPickerVc:(BOOL)pushPhotoPickerVc;
- (instancetype)initWithMaxImagesCount:(NSInteger)maxImagesCount columnNumber:(NSInteger)columnNumber delegate:(id<TZImagePickerControllerDelegate>)delegate showAlbumInPhotoPickerVc:(BOOL)showAlbumInPhotoPickerVc;
/// This init method just for previewing photos / 用这个初始化方法以预览图片
- (instancetype)initWithSelectedAssets:(NSMutableArray *)selectedAssets selectedPhotos:(NSMutableArray *)selectedPhotos index:(NSInteger)index;
/// This init method for crop photo / 用这个初始化方法以裁剪图片
Expand Down Expand Up @@ -345,6 +346,8 @@
@interface TZAlbumPickerController : UIViewController
@property (nonatomic, assign) NSInteger columnNumber;
@property (assign, nonatomic) BOOL isFirstAppear;
@property (nonatomic, assign) BOOL showAlbumInPhotoPickerVc;
@property (weak, nonatomic) UIViewController *photoPickerController;
- (void)configTableView;
@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ @interface TZImagePickerController () {
UIButton *_settingBtn;
BOOL _pushPhotoPickerVc;
BOOL _didPushPhotoPickerVc;
BOOL _showAlbumInPhotoPickerVc;
CGRect _cropRect;

UIButton *_progressHUD;
Expand Down Expand Up @@ -173,12 +174,31 @@ - (instancetype)initWithMaxImagesCount:(NSInteger)maxImagesCount columnNumber:(N
return [self initWithMaxImagesCount:maxImagesCount columnNumber:columnNumber delegate:delegate pushPhotoPickerVc:YES];
}

- (instancetype)initWithMaxImagesCount:(NSInteger)maxImagesCount columnNumber:(NSInteger)columnNumber delegate:(id<TZImagePickerControllerDelegate>)delegate pushPhotoPickerVc:(BOOL)pushPhotoPickerVc {
- (instancetype)initWithMaxImagesCount:(NSInteger)maxImagesCount columnNumber:(NSInteger)columnNumber delegate:(id<TZImagePickerControllerDelegate>)delegate showAlbumInPhotoPickerVc:(BOOL)showAlbumInPhotoPickerVc{
return [self initWithMaxImagesCount:maxImagesCount columnNumber:columnNumber delegate:delegate pushPhotoPickerVc:YES showAlbumInPhotoPickerVc:showAlbumInPhotoPickerVc];
}

- (instancetype)initWithMaxImagesCount:(NSInteger)maxImagesCount columnNumber:(NSInteger)columnNumber delegate:(id<TZImagePickerControllerDelegate>)delegate pushPhotoPickerVc:(BOOL)pushPhotoPickerVc{
return [self initWithMaxImagesCount:maxImagesCount columnNumber:columnNumber delegate:delegate pushPhotoPickerVc:pushPhotoPickerVc showAlbumInPhotoPickerVc:NO];
}

- (instancetype)initWithMaxImagesCount:(NSInteger)maxImagesCount columnNumber:(NSInteger)columnNumber delegate:(id<TZImagePickerControllerDelegate>)delegate pushPhotoPickerVc:(BOOL)pushPhotoPickerVc showAlbumInPhotoPickerVc:(BOOL)showAlbumInPhotoPickerVc{
_showAlbumInPhotoPickerVc = showAlbumInPhotoPickerVc;
_pushPhotoPickerVc = pushPhotoPickerVc;
TZAlbumPickerController *albumPickerVc = [[TZAlbumPickerController alloc] init];
albumPickerVc.isFirstAppear = YES;
albumPickerVc.columnNumber = columnNumber;
self = [super initWithRootViewController:albumPickerVc];

TZPhotoPickerController *photoPickerVc;
if (showAlbumInPhotoPickerVc) {
photoPickerVc = [[TZPhotoPickerController alloc] init];
photoPickerVc.showAlbumInPhotoPickerVc = showAlbumInPhotoPickerVc;
photoPickerVc.isFirstAppear = YES;
photoPickerVc.columnNumber = columnNumber;
self = [super initWithRootViewController:photoPickerVc];
}else{
TZAlbumPickerController *albumPickerVc = [[TZAlbumPickerController alloc] init];
albumPickerVc.isFirstAppear = YES;
albumPickerVc.columnNumber = columnNumber;
self = [super initWithRootViewController:albumPickerVc];
}
if (self) {
self.maxImagesCount = maxImagesCount > 0 ? maxImagesCount : 9; // Default is 9 / 默认最大可选9张图片
self.pickerDelegate = delegate;
Expand Down Expand Up @@ -224,7 +244,13 @@ - (instancetype)initWithMaxImagesCount:(NSInteger)maxImagesCount columnNumber:(N
_timer = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(observeAuthrizationStatusChange) userInfo:nil repeats:NO];
}
} else {
[self pushPhotoPickerVc];
if (showAlbumInPhotoPickerVc) {
[[TZImageManager manager] getCameraRollAlbumWithFetchAssets:NO completion:^(TZAlbumModel *model) {
photoPickerVc.model = model;
}];
}else{
[self pushPhotoPickerVc];
}
}
}
return self;
Expand Down Expand Up @@ -414,11 +440,21 @@ - (void)observeAuthrizationStatusChange {
[_tipLabel removeFromSuperview];
[_settingBtn removeFromSuperview];

[self pushPhotoPickerVc];

TZAlbumPickerController *albumPickerVc = (TZAlbumPickerController *)self.visibleViewController;
if ([albumPickerVc isKindOfClass:[TZAlbumPickerController class]]) {
[albumPickerVc configTableView];
if (_showAlbumInPhotoPickerVc) {
TZPhotoPickerController *photoPickerVc = (TZPhotoPickerController *)self.visibleViewController;
if ([photoPickerVc isKindOfClass:[TZPhotoPickerController class]]) {
[[TZImageManager manager] getCameraRollAlbumWithFetchAssets:NO completion:^(TZAlbumModel *model) {
photoPickerVc.model = model;
}];
[photoPickerVc updateAlbum];
}
}else{
[self pushPhotoPickerVc];

TZAlbumPickerController *albumPickerVc = (TZAlbumPickerController *)self.visibleViewController;
if ([albumPickerVc isKindOfClass:[TZAlbumPickerController class]]) {
[albumPickerVc configTableView];
}
}
}
}
Expand Down Expand Up @@ -819,6 +855,13 @@ - (void)configTableView {

if (!self->_tableView) {
self->_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
if (self.showAlbumInPhotoPickerVc) {
if (@available(iOS 11.0, *)) {
self->_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
} else {
self.automaticallyAdjustsScrollViewInsets = NO;
}
}
self->_tableView.rowHeight = 70;
if (@available(iOS 13.0, *)) {
self->_tableView.backgroundColor = [UIColor tertiarySystemBackgroundColor];
Expand Down Expand Up @@ -867,19 +910,24 @@ - (void)photoLibraryDidChange:(PHChange *)changeInstance {
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];

CGFloat top = 0;
CGFloat tableViewHeight = 0;
CGFloat naviBarHeight = self.navigationController.navigationBar.tz_height;
BOOL isStatusBarHidden = [UIApplication sharedApplication].isStatusBarHidden;
BOOL isFullScreen = self.view.tz_height == [UIScreen mainScreen].bounds.size.height;
if (self.navigationController.navigationBar.isTranslucent) {
top = naviBarHeight;
if (!isStatusBarHidden && isFullScreen) top += [TZCommonTools tz_statusBarHeight];
tableViewHeight = self.view.tz_height - top;
} else {
tableViewHeight = self.view.tz_height;
if (self.showAlbumInPhotoPickerVc) {
_tableView.frame = self.view.bounds;
}else{
CGFloat top = 0;
CGFloat tableViewHeight = 0;
CGFloat naviBarHeight = self.navigationController.navigationBar.tz_height;
BOOL isStatusBarHidden = [UIApplication sharedApplication].isStatusBarHidden;
BOOL isFullScreen = self.view.tz_height == [UIScreen mainScreen].bounds.size.height;
if (self.navigationController.navigationBar.isTranslucent) {
top = naviBarHeight;
if (!isStatusBarHidden && isFullScreen) top += [TZCommonTools tz_statusBarHeight];
tableViewHeight = self.view.tz_height - top;
} else {
tableViewHeight = self.view.tz_height;
}
_tableView.frame = CGRectMake(0, top, self.view.tz_width, tableViewHeight);
}
_tableView.frame = CGRectMake(0, top, self.view.tz_width, tableViewHeight);

TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController;
if (imagePickerVc.albumPickerPageDidLayoutSubviewsBlock) {
imagePickerVc.albumPickerPageDidLayoutSubviewsBlock(_tableView);
Expand All @@ -901,17 +949,28 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell.albumCellDidLayoutSubviewsBlock = imagePickerVc.albumCellDidLayoutSubviewsBlock;
cell.albumCellDidSetModelBlock = imagePickerVc.albumCellDidSetModelBlock;
cell.selectedCountButton.backgroundColor = imagePickerVc.iconThemeColor;
cell.showAlbumInPhotoPickerVc = self.showAlbumInPhotoPickerVc;
cell.model = _albumArr[indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
if ([self.photoPickerController isKindOfClass:[TZPhotoPickerController class]]){
TZPhotoPickerController *photoPickerVc = (TZPhotoPickerController *)self.photoPickerController;
cell.isSelected = [photoPickerVc.model.name isEqualToString:cell.model.name];
}
return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
TZPhotoPickerController *photoPickerVc = [[TZPhotoPickerController alloc] init];
photoPickerVc.columnNumber = self.columnNumber;
TZAlbumModel *model = _albumArr[indexPath.row];
photoPickerVc.model = model;
[self.navigationController pushViewController:photoPickerVc animated:YES];
if ([self.photoPickerController isKindOfClass:[TZPhotoPickerController class]]){
TZPhotoPickerController *photoPickerVc = (TZPhotoPickerController *)self.photoPickerController;
TZAlbumModel *model = _albumArr[indexPath.row];
photoPickerVc.model = model;
photoPickerVc.isShowAlbum = NO;
}else{
TZPhotoPickerController *photoPickerVc = [[TZPhotoPickerController alloc] init];
photoPickerVc.columnNumber = self.columnNumber;
TZAlbumModel *model = _albumArr[indexPath.row];
photoPickerVc.model = model;
[self.navigationController pushViewController:photoPickerVc animated:YES];
}
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,19 @@
@property (nonatomic, assign) BOOL isFirstAppear;
@property (nonatomic, assign) NSInteger columnNumber;
@property (nonatomic, strong) TZAlbumModel *model;
@property (nonatomic, assign) BOOL isShowAlbum;
@property (nonatomic, assign) BOOL showAlbumInPhotoPickerVc;

- (void)updateAlbum;
@end


@interface TZCollectionView : UICollectionView

@end

@interface TZPhotoPickerTitleView : UIView
@property (assign, nonatomic) BOOL isShowAlbum;
@property (strong, nonatomic) NSString *selectAlbumName;
- (CGSize)getSize;
@end