Commit 316b5ef2 authored by shuijing's avatar shuijing

【feat】图片选择器 ui重构

【影响范围】图片选择器
【风险评估】低
【是否自测】是
parent 76c60f86
......@@ -9,6 +9,11 @@
#import <UIKit/UIKit.h>
#import <Photos/Photos.h>
typedef NS_ENUM(NSUInteger, TZImagePickerTheme) {
TZImagePickerTheme_Normal = 0,
TZImagePickerTheme_New,
};
typedef enum : NSUInteger {
TZAssetCellTypePhoto = 0,
TZAssetCellTypeLivePhoto,
......@@ -35,6 +40,9 @@ typedef enum : NSUInteger {
@property (nonatomic, assign) BOOL showSelectBtn;
@property (assign, nonatomic) BOOL allowPreview;
@property (nonatomic, assign) BOOL hiddenSelectView; /// 图片满x张后 是否展示选择视图
@property (nonatomic, assign) TZImagePickerTheme pickerTheme;
@property (nonatomic, copy) void (^assetCellDidSetModelBlock)(TZAssetCell *cell, UIImageView *imageView, UIImageView *selectImageView, UILabel *indexLabel, UIView *bottomView, UILabel *timeLength, UIImageView *videoImgView);
@property (nonatomic, copy) void (^assetCellDidLayoutSubviewsBlock)(TZAssetCell *cell, UIImageView *imageView, UIImageView *selectImageView, UILabel *indexLabel, UIView *bottomView, UILabel *timeLength, UIImageView *videoImgView);
......@@ -44,7 +52,12 @@ typedef enum : NSUInteger {
@class TZAlbumModel;
@interface TZAlbumCell : UITableViewCell
@property (nonatomic, strong) TZAlbumModel *model;
@property (nonatomic, assign) TZImagePickerTheme pickerTheme;
@property (weak, nonatomic) UIButton *selectedCountButton;
@property (weak, nonatomic) UIImageView *arrowImgView;
@property (nonatomic, strong) UIImage *arrowSelImage;
@property (nonatomic, strong) UIImage *arrowDefImage;
@property (nonatomic, copy) void (^albumCellDidSetModelBlock)(TZAlbumCell *cell, UIImageView *posterImageView, UILabel *titleLabel);
@property (nonatomic, copy) void (^albumCellDidLayoutSubviewsBlock)(TZAlbumCell *cell, UIImageView *posterImageView, UILabel *titleLabel);
......@@ -53,4 +66,7 @@ typedef enum : NSUInteger {
@interface TZAssetCameraCell : UICollectionViewCell
@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UIView *coverView;
- (void)showCoverView:(BOOL)isShow coverColor:(UIColor *)coverColor;
@end
......@@ -74,6 +74,7 @@
} else {
[self cancelBigImageRequest];
}
[self setNeedsLayout];
if (self.assetCellDidSetModelBlock) {
......@@ -98,6 +99,13 @@
}
}
- (void)setHiddenSelectView:(BOOL)hiddenSelectView {
_hiddenSelectView = hiddenSelectView;
if (_pickerTheme == TZImagePickerTheme_New) {
self.selectImageView.hidden = hiddenSelectView;
}
}
- (void)setType:(TZAssetCellType)type {
_type = type;
if (type == TZAssetCellTypePhoto || type == TZAssetCellTypeLivePhoto || (type == TZAssetCellTypePhotoGif && !self.allowPickingGif) || self.allowPickingMultipleVideo) {
......@@ -236,12 +244,24 @@
self.index = [tzImagePickerVc.selectedAssetIds indexOfObject:self.model.asset.localIdentifier] + 1;
}
self.indexLabel.hidden = !self.selectPhotoButton.isSelected;
self.showSelectBtn = tzImagePickerVc.showSelectBtn;
BOOL notSelectable = [TZCommonTools isAssetNotSelectable:self.model tzImagePickerVc:tzImagePickerVc];
if (notSelectable && tzImagePickerVc.showPhotoCannotSelectLayer && !self.model.isSelected) {
self.cannotSelectLayerButton.backgroundColor = tzImagePickerVc.cannotSelectLayerColor;
self.cannotSelectLayerButton.hidden = NO;
self.hiddenSelectView = YES;
} else {
self.cannotSelectLayerButton.hidden = YES;
self.hiddenSelectView = NO;
}
if (self.model.isSelected && tzImagePickerVc.iconThemeColor && tzImagePickerVc.showSelectedIndex) {
/// 需要边框颜色
[self.layer setBorderWidth:2];
[self.layer setBorderColor:[tzImagePickerVc.iconThemeColor CGColor]];
} else {
[self.layer setBorderWidth:0];
}
}
......@@ -330,7 +350,7 @@
if (_indexLabel == nil) {
UILabel *indexLabel = [[UILabel alloc] init];
indexLabel.font = [UIFont systemFontOfSize:14];
indexLabel.adjustsFontSizeToFitWidth = YES;
// indexLabel.adjustsFontSizeToFitWidth = YES;
indexLabel.textColor = [UIColor whiteColor];
indexLabel.textAlignment = NSTextAlignmentCenter;
[self.contentView addSubview:indexLabel];
......@@ -356,12 +376,19 @@
} else {
_selectPhotoButton.frame = self.bounds;
}
_selectImageView.frame = CGRectMake(self.tz_width - 27, 3, 24, 24);
if (_selectImageView.image.size.width <= 27) {
_selectImageView.contentMode = UIViewContentModeCenter;
} else {
_selectImageView.contentMode = UIViewContentModeScaleAspectFit;
}
if (self.pickerTheme == TZImagePickerTheme_New) {
_selectImageView.frame = CGRectMake(self.tz_width - 20 - 8, 8, 20, 20);
_selectImageView.contentMode = UIViewContentModeScaleAspectFit;
}
_indexLabel.frame = _selectImageView.frame;
_imageView.frame = self.bounds;
......@@ -411,23 +438,39 @@
_model = model;
UIColor *nameColor = UIColor.blackColor;
UIColor *countColor = [UIColor lightGrayColor];
CGFloat font = 16;
if (@available(iOS 13.0, *)) {
nameColor = UIColor.labelColor;
}
NSMutableAttributedString *nameString = [[NSMutableAttributedString alloc] initWithString:model.name attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16],NSForegroundColorAttributeName:nameColor}];
NSAttributedString *countString = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@" (%zd)",model.count] attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16],NSForegroundColorAttributeName:[UIColor lightGrayColor]}];
if (self.pickerTheme == TZImagePickerTheme_New) {
nameColor = UIColor.whiteColor;
countColor = [UIColor colorWithRed:128.0/255 green:128.0/255 blue:128.0/255 alpha:1];
self.backgroundColor = [UIColor colorWithRed:27.0/255 green:27.0/255 blue:27.0/255 alpha:1];
font = 14;
}
NSMutableAttributedString *nameString = [[NSMutableAttributedString alloc] initWithString:model.name attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:font],NSForegroundColorAttributeName:nameColor}];
NSAttributedString *countString = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@" (%zd)",model.count] attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:font],NSForegroundColorAttributeName:countColor}];
[nameString appendAttributedString:countString];
self.titleLabel.attributedText = nameString;
[[TZImageManager manager] getPostImageWithAlbumModel:model completion:^(UIImage *postImage) {
self.posterImageView.image = postImage;
[self setNeedsLayout];
}];
if (self.pickerTheme == TZImagePickerTheme_New) {
self.selectedCountButton.hidden = YES;
self.arrowImgView.hidden = NO;
[self.arrowImgView setImage: model.selectedCount ? self.arrowSelImage : self.arrowDefImage];
} else {
self.arrowImgView.hidden = YES;
if (model.selectedCount) {
self.selectedCountButton.hidden = NO;
[self.selectedCountButton setTitle:[NSString stringWithFormat:@"%zd",model.selectedCount] forState:UIControlStateNormal];
} else {
self.selectedCountButton.hidden = YES;
}
}
if (self.albumCellDidSetModelBlock) {
self.albumCellDidSetModelBlock(self, _posterImageView, _titleLabel);
......@@ -436,10 +479,12 @@
- (void)layoutSubviews {
[super layoutSubviews];
_selectedCountButton.frame = CGRectMake(self.contentView.tz_width - 24, 23, 24, 24);
_selectedCountButton.frame = CGRectMake(self.contentView.tz_width - 24, (self.tz_height - 24) / 2, 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);
CGFloat originX = self.pickerTheme == TZImagePickerTheme_New ? 72: 80;
self.titleLabel.frame = CGRectMake(originX, (self.tz_height - titleHeight) / 2, self.tz_width - originX - 50, titleHeight);
self.posterImageView.frame = CGRectMake(0, 0, self.tz_height, self.tz_height);
self.arrowImgView.frame = CGRectMake(self.tz_width - 12 - 12, (self.tz_height - 12) * 0.5, 12, 12);
if (self.albumCellDidLayoutSubviewsBlock) {
self.albumCellDidLayoutSubviewsBlock(self, _posterImageView, _titleLabel);
......@@ -472,7 +517,6 @@
} else {
titleLabel.textColor = [UIColor blackColor];
}
titleLabel.textAlignment = NSTextAlignmentLeft;
[self.contentView addSubview:titleLabel];
_titleLabel = titleLabel;
}
......@@ -494,6 +538,16 @@
return _selectedCountButton;
}
- (UIImageView *)arrowImgView {
if (_arrowImgView == nil) {
UIImageView *imageView = [[UIImageView alloc] init];
imageView.hidden = YES;
[self.contentView addSubview:imageView];
_arrowImgView = imageView;
}
return _arrowImgView;
}
@end
......@@ -503,19 +557,44 @@
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor whiteColor];
_imageView = [[UIImageView alloc] init];
_imageView.backgroundColor = [UIColor colorWithWhite:1.000 alpha:0.500];
_imageView.contentMode = UIViewContentModeScaleAspectFill;
[self.contentView addSubview:_imageView];
_coverView = [[UIView alloc] init];
_coverView.hidden = YES;
[self.contentView addSubview:_coverView];
self.clipsToBounds = YES;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reload:) name:@"TZ_PHOTO_PICKER_RELOAD_NOTIFICATION" object:nil];
}
return self;
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)layoutSubviews {
[super layoutSubviews];
_imageView.frame = self.bounds;
_coverView.frame = self.bounds;
}
- (void)reload:(NSNotification *)noti {
TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)noti.object;
if (tzImagePickerVc.selectedAssetIds.count >= tzImagePickerVc.maxImagesCount) {
[self showCoverView:YES coverColor:tzImagePickerVc.cannotSelectLayerColor];
} else {
[self showCoverView:NO coverColor:tzImagePickerVc.cannotSelectLayerColor];
}
}
- (void)showCoverView:(BOOL)isShow coverColor:(UIColor *)coverColor {
_coverView.hidden = !isShow;
_coverView.backgroundColor = coverColor;
}
@end
......@@ -40,6 +40,9 @@ typedef enum : NSUInteger {
@property (nonatomic, strong) NSString *name; ///< The album name
@property (nonatomic, assign) NSInteger count; ///< Count of photos the album contain
@property (nonatomic, strong) UIColor *countColor;
@property (nonatomic, strong) PHFetchResult *result;
@property (nonatomic, strong) PHAssetCollection *collection;
@property (nonatomic, strong) PHFetchOptions *options;
......
......@@ -281,16 +281,16 @@ static dispatch_once_t onceToken;
- (NSString *)getNewTimeFromDurationSecond:(NSInteger)duration {
NSString *newTime;
if (duration < 10) {
newTime = [NSString stringWithFormat:@"0:0%zd",duration];
newTime = [NSString stringWithFormat:@"00:00:0%zd",duration];
} else if (duration < 60) {
newTime = [NSString stringWithFormat:@"0:%zd",duration];
newTime = [NSString stringWithFormat:@"00:00:%zd",duration];
} else {
NSInteger min = duration / 60;
NSInteger sec = duration - (min * 60);
if (sec < 10) {
newTime = [NSString stringWithFormat:@"%zd:0%zd",min,sec];
newTime = [NSString stringWithFormat:@"00:%zd:0%zd",min,sec];
} else {
newTime = [NSString stringWithFormat:@"%zd:%zd",min,sec];
newTime = [NSString stringWithFormat:@"00:%zd:%zd",min,sec];
}
}
return newTime;
......
......@@ -25,8 +25,9 @@
#import "TZLocationManager.h"
#import "TZPhotoPreviewController.h"
#import "TZPhotoPreviewCell.h"
#import "TZAssetCell.h"
@class TZAlbumCell, TZAssetCell;
@class TZAlbumCell;
@protocol TZImagePickerControllerDelegate;
@interface TZImagePickerController : UINavigationController
......@@ -91,6 +92,9 @@
/// 默认是30s,如果超过视频时长,则为视频时长,小于1s不裁剪
@property (nonatomic, assign) NSInteger maxCropVideoDuration;
/// 选择视频最长时间 默认是30
@property (nonatomic, assign) NSInteger maxPickVideoDuration;
/// Default is NO, if set YES, The edited video will be automatically saved to the album.
/// 默认为NO,如果设置为YES,编辑后的视频会自动保存到相册
@property (nonatomic, assign) BOOL saveEditedVideoToAlbum;
......@@ -161,6 +165,8 @@
@property (nonatomic, strong) NSMutableArray *selectedAssets;
@property (nonatomic, strong) NSMutableArray<TZAssetModel *> *selectedModels;
@property (nonatomic, strong) NSMutableArray *selectedAssetIds;
/// 直接选中相册中的部分图片
- (void)addOriginalAssets:(NSArray *)originalAssets;
- (void)addSelectedModel:(TZAssetModel *)model;
- (void)removeSelectedModel:(TZAssetModel *)model;
......@@ -190,10 +196,12 @@
@property (nonatomic, copy) void (^cropViewSettingBlock)(UIView *cropView); ///< 自定义裁剪框的其他属性
@property (nonatomic, copy) void (^navLeftBarButtonSettingBlock)(UIButton *leftButton); ///< 自定义返回按钮样式及其属性
@property (nonatomic, assign) NSInteger albumCellHeight; /// 默认高度为70
/// 【自定义各页面/组件的样式】在界面初始化/组件setModel完成后调用,允许外界修改样式等
@property (nonatomic, copy) void (^photoPickerPageUIConfigBlock)(UICollectionView *collectionView, UIView *bottomToolBar, UIButton *previewButton, UIButton *originalPhotoButton, UILabel *originalPhotoLabel, UIButton *doneButton, UIImageView *numberImageView, UILabel *numberLabel, UIView *divideLine);
@property (nonatomic, copy) void (^photoPreviewPageUIConfigBlock)(UICollectionView *collectionView, UIView *naviBar, UIButton *backButton, UIButton *selectButton, UILabel *indexLabel, UIView *toolBar, UIButton *originalPhotoButton, UILabel *originalPhotoLabel, UIButton *doneButton, UIImageView *numberImageView, UILabel *numberLabel);
@property (nonatomic, copy) void (^videoPreviewPageUIConfigBlock)(UIButton *playButton, UIView *toolBar, UIButton *editBtn, UIButton *doneButton);
@property (nonatomic, copy) void (^photoPreviewPageUIConfigBlock)(UICollectionView *collectionView, UIView *naviBar, UIButton *backButton, UILabel *titleLabel, UIButton *selectButton, UILabel *indexLabel, UIView *toolBar, UIButton *originalPhotoButton, UILabel *originalPhotoLabel, UIButton *doneButton, UIImageView *numberImageView, UILabel *numberLabel);
@property (nonatomic, copy) void (^videoPreviewPageUIConfigBlock)(UIView *navBar, UIButton *backButton, UIButton *playButton, UIView *toolBar, UIButton *editBtn, UIButton *doneButton);
@property (nonatomic, copy) void (^videoEditViewPageUIConfigBlock)(UIButton *playButton,UILabel *cropVideoDurationLabel, UIButton *editButton, UIButton *doneButton);
@property (nonatomic, copy) void (^gifPreviewPageUIConfigBlock)(UIView *toolBar, UIButton *doneButton);
@property (nonatomic, copy) void (^albumPickerPageUIConfigBlock)(UITableView *tableView);
......@@ -201,8 +209,8 @@
@property (nonatomic, copy) void (^albumCellDidSetModelBlock)(TZAlbumCell *cell, UIImageView *posterImageView, UILabel *titleLabel);
/// 【自定义各页面/组件的frame】在界面viewDidLayoutSubviews/组件layoutSubviews后调用,允许外界修改frame等
@property (nonatomic, copy) void (^photoPickerPageDidLayoutSubviewsBlock)(UICollectionView *collectionView, UIView *bottomToolBar, UIButton *previewButton, UIButton *originalPhotoButton, UILabel *originalPhotoLabel, UIButton *doneButton, UIImageView *numberImageView, UILabel *numberLabel, UIView *divideLine);
@property (nonatomic, copy) void (^photoPreviewPageDidLayoutSubviewsBlock)(UICollectionView *collectionView, UIView *naviBar, UIButton *backButton, UIButton *selectButton, UILabel *indexLabel, UIView *toolBar, UIButton *originalPhotoButton, UILabel *originalPhotoLabel, UIButton *doneButton, UIImageView *numberImageView, UILabel *numberLabel);
@property (nonatomic, copy) void (^videoPreviewPageDidLayoutSubviewsBlock)(UIButton *playButton, UIView *toolBar, UIButton *editButton, UIButton *doneButton);
@property (nonatomic, copy) void (^photoPreviewPageDidLayoutSubviewsBlock)(UICollectionView *collectionView, UIView *naviBar, UIButton *backButton, UILabel *titleLabel, UIButton *selectButton, UILabel *indexLabel, UIView *toolBar, UIButton *originalPhotoButton, UILabel *originalPhotoLabel, UIButton *doneButton, UIImageView *numberImageView, UILabel *numberLabel);
@property (nonatomic, copy) void (^videoPreviewPageDidLayoutSubviewsBlock)(UIView *navBar, UIButton *backButton, UIButton *playButton, UIView *toolBar, UIButton *editButton, UIButton *doneButton);
@property (nonatomic, copy) void (^videoEditViewPageDidLayoutSubviewsBlock)(UIButton *playButton, UILabel *cropVideoDurationLabel, UIButton *cancelButton, UIButton *doneButton);
@property (nonatomic, copy) void (^gifPreviewPageDidLayoutSubviewsBlock)(UIView *toolBar, UIButton *doneButton);
@property (nonatomic, copy) void (^albumPickerPageDidLayoutSubviewsBlock)(UITableView *tableView);
......@@ -211,7 +219,7 @@
/// 自定义各页面/组件的frame】刷新底部状态(refreshNaviBarAndBottomBarState)使用的
@property (nonatomic, copy) void (^photoPickerPageDidRefreshStateBlock)(UICollectionView *collectionView, UIView *bottomToolBar, UIButton *previewButton, UIButton *originalPhotoButton, UILabel *originalPhotoLabel, UIButton *doneButton, UIImageView *numberImageView, UILabel *numberLabel, UIView *divideLine);
@property (nonatomic, copy) void (^photoPreviewPageDidRefreshStateBlock)(UICollectionView *collectionView, UIView *naviBar, UIButton *backButton, UIButton *selectButton, UILabel *indexLabel, UIView *toolBar, UIButton *originalPhotoButton, UILabel *originalPhotoLabel, UIButton *doneButton, UIImageView *numberImageView, UILabel *numberLabel);
@property (nonatomic, copy) void (^photoPreviewPageDidRefreshStateBlock)(UICollectionView *collectionView, UIView *naviBar, UIButton *backButton, UILabel *titleLabel, UIButton *selectButton, UILabel *indexLabel, UIView *toolBar, UIButton *originalPhotoButton, UILabel *originalPhotoLabel, UIButton *doneButton, UIImageView *numberImageView, UILabel *numberLabel);
#pragma mark -
- (UIAlertController *)showAlertWithTitle:(NSString *)title;
......@@ -236,6 +244,9 @@
@property (nonatomic, strong) UIImage *photoPreviewOriginDefImage;
@property (nonatomic, strong) UIImage *photoNumberIconImage;
@property (nonatomic, strong) UIImage *arrowSelImage;
@property (nonatomic, strong) UIImage *arrowDefImage;
#pragma mark -
/// Appearance / 外观颜色 + 按钮文字
@property (nonatomic, strong) UIColor *oKButtonTitleColorNormal;
......@@ -258,6 +269,7 @@
/// Icon theme color, default is green color like wechat, the value is r:31 g:185 b:34. Currently only support image selection icon when showSelectedIndex is YES. If you need it, please set it as soon as possible
/// icon主题色,默认是微信的绿色,值是r:31 g:185 b:34。目前仅支持showSelectedIndex为YES时的图片选中icon。如需要,请尽早设置它。
@property (strong, nonatomic) UIColor *iconThemeColor;
@property (nonatomic, assign) TZImagePickerTheme pickerTheme;
#pragma mark -
- (void)cancelButtonClick;
......@@ -270,6 +282,11 @@
@property (nonatomic, copy) void (^didFinishPickingAndEditingVideoHandle)(UIImage *coverImage,NSString *outputPath,NSString *errorMsg);
@property (nonatomic, copy) void (^didFinishPickingGifImageHandle)(UIImage *animatedImage,id sourceAssets);
@property (nonatomic, copy) void (^didAlbumCellDidClickBlock)(void);
/// 将弹窗效果交由外部完成
@property (nonatomic, copy) void (^didShowAlertStringBlock)(NSString *alertString);
@property (nonatomic, weak) id<TZImagePickerControllerDelegate> pickerDelegate;
@end
......
......@@ -305,6 +305,7 @@
self.allowCameraLocation = YES;
self.presetName = AVAssetExportPresetMediumQuality;
self.maxCropVideoDuration = 30;
self.maxPickVideoDuration = 30;
self.iconThemeColor = [UIColor colorWithRed:31 / 255.0 green:185 / 255.0 blue:34 / 255.0 alpha:1.0];
[self configDefaultBtnTitle];
......@@ -437,6 +438,10 @@
}
- (UIAlertController *)showAlertWithTitle:(NSString *)title {
if (self.didShowAlertStringBlock) {
self.didShowAlertStringBlock(title);
return nil;
}
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:[NSBundle tz_localizedStringForKey:@"OK"] style:UIAlertActionStyleDefault handler:nil]];
[self presentViewController:alertController animated:YES completion:nil];
......@@ -618,6 +623,28 @@
}
}
/// 直接选中相册中的部分图片
- (void)addOriginalAssets:(NSArray *)originalAssets {
if (!_selectedAssets) {
_selectedAssets = [NSMutableArray array];
}
if (!_selectedModels) {
_selectedModels = [NSMutableArray array];
}
if (!_selectedAssetIds) {
_selectedAssetIds = [NSMutableArray array];
}
[_selectedAssets addObjectsFromArray:originalAssets];
for (PHAsset *asset in originalAssets) {
TZAssetModel *model = [TZAssetModel modelWithAsset:asset type:[[TZImageManager manager] getAssetType:asset]];
model.isSelected = YES;
[self addSelectedModel:model];
}
/// 通知刷新
[[NSNotificationCenter defaultCenter] postNotificationName:@"TZ_PHOTO_PICKER_SELECTED_RELOAD" object:nil];
}
- (void)setAllowPickingImage:(BOOL)allowPickingImage {
_allowPickingImage = allowPickingImage;
[TZImagePickerConfig sharedInstance].allowPickingImage = allowPickingImage;
......@@ -752,6 +779,7 @@
UITableView *_tableView;
}
@property (nonatomic, strong) NSMutableArray *albumArr;
@property (nonatomic, assign) TZImagePickerTheme pickerTheme;
@end
@implementation TZAlbumPickerController
......@@ -771,6 +799,7 @@
TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController;
UIBarButtonItem *cancelItem = [[UIBarButtonItem alloc] initWithTitle:imagePickerVc.cancelBtnTitleStr style:UIBarButtonItemStylePlain target:imagePickerVc action:@selector(cancelButtonClick)];
[TZCommonTools configBarButtonItem:cancelItem tzImagePickerVc:imagePickerVc];
self.pickerTheme = imagePickerVc.pickerTheme;
self.navigationItem.rightBarButtonItem = cancelItem;
}
......@@ -817,12 +846,16 @@
if (!self->_tableView) {
self->_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
self->_tableView.rowHeight = 70;
self->_tableView.rowHeight = self.pickerTheme == TZImagePickerTheme_New ? 60: 70;
if (@available(iOS 13.0, *)) {
self->_tableView.backgroundColor = [UIColor tertiarySystemBackgroundColor];
} else {
self->_tableView.backgroundColor = [UIColor whiteColor];
}
if (self.pickerTheme == TZImagePickerTheme_New) {
self->_tableView.backgroundColor = [UIColor colorWithRed:30.0/255 green:30.0/255 blue:30.0/255 alpha:1];
self->_tableView.separatorColor = [UIColor colorWithRed:62.0/255 green:62.0/255 blue:62.0/255 alpha:1];
}
self->_tableView.tableFooterView = [[UIView alloc] init];
self->_tableView.dataSource = self;
self->_tableView.delegate = self;
......@@ -896,11 +929,15 @@
cell.backgroundColor = UIColor.tertiarySystemBackgroundColor;
}
TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController;
cell.pickerTheme = imagePickerVc.pickerTheme;
cell.arrowDefImage = imagePickerVc.arrowDefImage;
cell.arrowSelImage = imagePickerVc.arrowSelImage;
cell.albumCellDidLayoutSubviewsBlock = imagePickerVc.albumCellDidLayoutSubviewsBlock;
cell.albumCellDidSetModelBlock = imagePickerVc.albumCellDidSetModelBlock;
cell.selectedCountButton.backgroundColor = imagePickerVc.iconThemeColor;
cell.model = _albumArr[indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.accessoryType = cell.pickerTheme == TZImagePickerTheme_New ? UITableViewCellAccessoryNone: UITableViewCellAccessoryDisclosureIndicator;
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
return cell;
}
......
......@@ -108,6 +108,7 @@ static CGFloat itemMargin = 5;
_showTakePhotoBtn = _model.isCameraRoll && ((tzImagePickerVc.allowTakePicture && tzImagePickerVc.allowPickingImage) || (tzImagePickerVc.allowTakeVideo && tzImagePickerVc.allowPickingVideo));
// [self resetCachedAssets];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didChangeStatusBarOrientationNotification:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didSelectedRefresh) name:@"TZ_PHOTO_PICKER_SELECTED_RELOAD" object:nil];
self.operationQueue = [[NSOperationQueue alloc] init];
self.operationQueue.maxConcurrentOperationCount = 3;
......@@ -572,10 +573,16 @@ static CGFloat itemMargin = 5;
} else {
cell.imageView.backgroundColor = [UIColor colorWithWhite:1.000 alpha:0.500];
}
if (tzImagePickerVc.selectedAssetIds.count >= tzImagePickerVc.maxImagesCount) {
[cell showCoverView:YES coverColor:tzImagePickerVc.cannotSelectLayerColor];
} else {
[cell showCoverView:NO coverColor:tzImagePickerVc.cannotSelectLayerColor];
}
return cell;
}
// the cell dipaly photo or video / 展示照片或视频的cell
TZAssetCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TZAssetCell" forIndexPath:indexPath];
cell.pickerTheme = tzImagePickerVc.pickerTheme;
cell.allowPickingMultipleVideo = tzImagePickerVc.allowPickingMultipleVideo;
cell.photoDefImage = tzImagePickerVc.photoDefImage;
cell.photoSelImage = tzImagePickerVc.photoSelImage;
......@@ -599,14 +606,25 @@ static CGFloat itemMargin = 5;
if (notSelectable && tzImagePickerVc.showPhotoCannotSelectLayer && !model.isSelected) {
cell.cannotSelectLayerButton.backgroundColor = tzImagePickerVc.cannotSelectLayerColor;
cell.cannotSelectLayerButton.hidden = NO;
cell.hiddenSelectView = YES;
} else {
cell.cannotSelectLayerButton.hidden = YES;
cell.hiddenSelectView = NO;
}
if (model.isSelected && tzImagePickerVc.iconThemeColor && tzImagePickerVc.showSelectedIndex) {
/// 需要边框颜色
[cell.layer setBorderWidth:2];
[cell.layer setBorderColor:[tzImagePickerVc.iconThemeColor CGColor]];
} else {
[cell.layer setBorderWidth:0];
}
__weak typeof(cell) weakCell = cell;
__weak typeof(self) weakSelf = self;
__weak typeof(_numberImageView.layer) weakLayer = _numberImageView.layer;
cell.didSelectPhotoBlock = ^(BOOL isSelected) {
__strong typeof(weakCell) strongCell = weakCell;
__strong typeof(weakSelf) strongSelf = weakSelf;
__strong typeof(weakLayer) strongLayer = weakLayer;
......@@ -672,7 +690,14 @@ static CGFloat itemMargin = 5;
// take a photo / 去拍照
TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
if (((tzImagePickerVc.sortAscendingByModificationDate && indexPath.item >= _models.count) || (!tzImagePickerVc.sortAscendingByModificationDate && indexPath.item == 0)) && _showTakePhotoBtn) {
[self takePhoto]; return;
if (tzImagePickerVc.pickerTheme == TZImagePickerTheme_New) {
if (tzImagePickerVc.didAlbumCellDidClickBlock) {
tzImagePickerVc.didAlbumCellDidClickBlock();
return;
}
}
[self takePhoto];
return;
}
// preview phote or video / 预览照片或视频
NSInteger index = indexPath.item;
......@@ -685,6 +710,11 @@ static CGFloat itemMargin = 5;
TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController;
[imagePickerVc showAlertWithTitle:[NSBundle tz_localizedStringForKey:@"Can not choose both video and photo"]];
} else {
if (model.asset.duration > tzImagePickerVc.maxPickVideoDuration) {
NSString *title = [NSString stringWithFormat:[NSBundle tz_localizedStringForKey:@"Can not choose video of duration over max"], tzImagePickerVc.maxPickVideoDuration];
[tzImagePickerVc showAlertWithTitle:title];
return;
}
TZVideoPlayerController *videoPlayerVc = [[TZVideoPlayerController alloc] init];
videoPlayerVc.model = model;
[self.navigationController pushViewController:videoPlayerVc animated:YES];
......@@ -782,6 +812,12 @@ static CGFloat itemMargin = 5;
}
}
- (void)didSelectedRefresh {
[self.collectionView reloadData];
[self refreshBottomToolBarStatus];
[self doneButtonClick];
}
- (void)refreshBottomToolBarStatus {
TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
......
......@@ -21,6 +21,7 @@
NSArray *_assetsTemp;
UIView *_naviBar;
UILabel *_titleLabel;
UIButton *_backButton;
UIButton *_selectButton;
UILabel *_indexLabel;
......@@ -110,6 +111,11 @@
[_backButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[_backButton addTarget:self action:@selector(backButtonClick) forControlEvents:UIControlEventTouchUpInside];
_titleLabel = [[UILabel alloc] init];
_titleLabel.font = [UIFont systemFontOfSize:14];
_titleLabel.textColor = [UIColor whiteColor];
_titleLabel.textAlignment = NSTextAlignmentCenter;
_selectButton = [[UIButton alloc] initWithFrame:CGRectZero];
[_selectButton setImage:tzImagePickerVc.photoDefImage forState:UIControlStateNormal];
[_selectButton setImage:tzImagePickerVc.photoSelImage forState:UIControlStateSelected];
......@@ -120,12 +126,13 @@
_selectButton.hidden = !tzImagePickerVc.showSelectBtn;
_indexLabel = [[UILabel alloc] init];
_indexLabel.adjustsFontSizeToFitWidth = YES;
// _indexLabel.adjustsFontSizeToFitWidth = YES;
_indexLabel.font = [UIFont systemFontOfSize:14];
_indexLabel.textColor = [UIColor whiteColor];
_indexLabel.textAlignment = NSTextAlignmentCenter;
[_naviBar addSubview:_selectButton];
[_naviBar addSubview:_titleLabel];
[_naviBar addSubview:_indexLabel];
[_naviBar addSubview:_backButton];
[self.view addSubview:_naviBar];
......@@ -191,7 +198,7 @@
[self.view addSubview:_toolBar];
if (_tzImagePickerVc.photoPreviewPageUIConfigBlock) {
_tzImagePickerVc.photoPreviewPageUIConfigBlock(_collectionView, _naviBar, _backButton, _selectButton, _indexLabel, _toolBar, _originalPhotoButton, _originalPhotoLabel, _doneButton, _numberImageView, _numberLabel);
_tzImagePickerVc.photoPreviewPageUIConfigBlock(_collectionView, _naviBar, _backButton, _titleLabel, _selectButton, _indexLabel, _toolBar, _originalPhotoButton, _originalPhotoLabel, _doneButton, _numberImageView, _numberLabel);
}
}
......@@ -266,6 +273,7 @@
CGFloat naviBarHeight = statusBarHeight + _tzImagePickerVc.navigationBar.tz_height;
_naviBar.frame = CGRectMake(0, 0, self.view.tz_width, naviBarHeight);
_backButton.frame = CGRectMake(10, 10 + statusBarHeightInterval, 44, 44);
_titleLabel.frame = CGRectMake((self.view.tz_width - 180) * 0.5, 10 + statusBarHeightInterval, 180, 44);
_selectButton.frame = CGRectMake(self.view.tz_width - 56, 10 + statusBarHeightInterval, 44, 44);
_indexLabel.frame = _selectButton.frame;
......@@ -298,7 +306,7 @@
[self configCropView];
if (_tzImagePickerVc.photoPreviewPageDidLayoutSubviewsBlock) {
_tzImagePickerVc.photoPreviewPageDidLayoutSubviewsBlock(_collectionView, _naviBar, _backButton, _selectButton, _indexLabel, _toolBar, _originalPhotoButton, _originalPhotoLabel, _doneButton, _numberImageView, _numberLabel);
_tzImagePickerVc.photoPreviewPageDidLayoutSubviewsBlock(_collectionView, _naviBar, _backButton, _titleLabel, _selectButton, _indexLabel, _toolBar, _originalPhotoButton, _originalPhotoLabel, _doneButton, _numberImageView, _numberLabel);
}
}
......@@ -569,6 +577,10 @@
TZAssetModel *model = _models[self.currentIndex];
_selectButton.selected = model.isSelected;
[self refreshSelectButtonImageViewContentMode];
NSString *index = [NSString stringWithFormat:@"%d", (int)([self.models indexOfObject:model] + 1)];
_titleLabel.text = [NSString stringWithFormat:@"%@/%d", index, self.models.count];
if (_selectButton.isSelected && _tzImagePickerVc.showSelectedIndex && _tzImagePickerVc.showSelectBtn) {
NSString *index = [NSString stringWithFormat:@"%d", (int)([_tzImagePickerVc.selectedAssetIds indexOfObject:model.asset.localIdentifier] + 1)];
_indexLabel.text = index;
......@@ -610,7 +622,7 @@
// iCloud同步失败的UI刷新
[self didICloudSyncStatusChanged:model];
if (_tzImagePickerVc.photoPreviewPageDidRefreshStateBlock) {
_tzImagePickerVc.photoPreviewPageDidRefreshStateBlock(_collectionView, _naviBar, _backButton, _selectButton, _indexLabel, _toolBar, _originalPhotoButton, _originalPhotoLabel, _doneButton, _numberImageView, _numberLabel);
_tzImagePickerVc.photoPreviewPageDidRefreshStateBlock(_collectionView, _naviBar, _backButton, _titleLabel, _selectButton, _indexLabel, _toolBar, _originalPhotoButton, _originalPhotoLabel, _doneButton, _numberImageView, _numberLabel);
}
}
......
......@@ -23,6 +23,9 @@
NSString *_outputPath;
NSString *_errorMsg;
UIView *_naviBar;
UIButton *_backButton;
UIView *_toolBar;
UIButton *_doneButton;
UIButton *_editButton;
......@@ -47,15 +50,14 @@
self.needShowStatusBar = ![UIApplication sharedApplication].statusBarHidden;
self.view.backgroundColor = [UIColor blackColor];
TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
if (tzImagePickerVc) {
self.navigationItem.title = tzImagePickerVc.previewBtnTitleStr;
}
[self configCustomNaviBar];
[self configMoviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pausePlayerAndShowNaviBar) name:UIApplicationWillResignActiveNotification object:nil];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES];
_originStatusBarStyle = [UIApplication sharedApplication].statusBarStyle;
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
}
......@@ -65,6 +67,7 @@
if (self.needShowStatusBar) {
[UIApplication sharedApplication].statusBarHidden = NO;
}
[self.navigationController setNavigationBarHidden:NO animated:YES];
[UIApplication sharedApplication].statusBarStyle = _originStatusBarStyle;
}
......@@ -92,6 +95,25 @@
}];
}
- (void)configCustomNaviBar {
TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
_naviBar = [[UIView alloc] initWithFrame:CGRectZero];
_naviBar.backgroundColor = [UIColor colorWithRed:(34/255.0) green:(34/255.0) blue:(34/255.0) alpha:0.7];
_backButton = [[UIButton alloc] initWithFrame:CGRectZero];
[_backButton setImage:[UIImage tz_imageNamedFromMyBundle:@"navi_back"] forState:UIControlStateNormal];
[_backButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[_backButton addTarget:self action:@selector(backButtonClick) forControlEvents:UIControlEventTouchUpInside];
[_naviBar addSubview:_backButton];
[self.view addSubview:_naviBar];
}
- (void)backButtonClick {
[self.navigationController popViewControllerAnimated:YES];
}
/// Show progress,do it next time / 给播放器添加进度更新,下次加上
- (void)addProgressObserver{
AVPlayerItem *playerItem = _player.currentItem;
......@@ -150,7 +172,7 @@
}
if (tzImagePickerVc.videoPreviewPageUIConfigBlock) {
tzImagePickerVc.videoPreviewPageUIConfigBlock(_playButton, _toolBar, _editButton, _doneButton);
tzImagePickerVc.videoPreviewPageUIConfigBlock(_naviBar, _backButton, _playButton, _toolBar, _editButton, _doneButton);
}
}
......@@ -171,6 +193,10 @@
BOOL isFullScreen = self.view.tz_height == [UIScreen mainScreen].bounds.size.height;
CGFloat statusBarHeight = isFullScreen ? [TZCommonTools tz_statusBarHeight] : 0;
CGFloat statusBarAndNaviBarHeight = statusBarHeight + self.navigationController.navigationBar.tz_height;
CGFloat naviBarHeight = statusBarHeight + tzImagePickerVc.navigationBar.tz_height;
CGFloat statusBarHeightInterval = isFullScreen ? (statusBarHeight - 20) : 0;
_naviBar.frame = CGRectMake(0, 0, self.view.tz_width, naviBarHeight);
_backButton.frame = CGRectMake(10, 10 + statusBarHeightInterval, 44, 44);
_playerLayer.frame = self.view.bounds;
CGFloat toolBarHeight = 44 + [TZCommonTools tz_safeAreaInsets].bottom;
_toolBar.frame = CGRectMake(0, self.view.tz_height - toolBarHeight, self.view.tz_width, toolBarHeight);
......@@ -183,7 +209,7 @@
_editButton.tz_height = 44;
}
if (tzImagePickerVc.videoPreviewPageDidLayoutSubviewsBlock) {
tzImagePickerVc.videoPreviewPageDidLayoutSubviewsBlock(_playButton, _toolBar, _editButton, _doneButton);
tzImagePickerVc.videoPreviewPageDidLayoutSubviewsBlock(_naviBar, _backButton, _playButton, _toolBar, _editButton, _doneButton);
}
}
......@@ -198,6 +224,7 @@
[_player play];
[self.navigationController setNavigationBarHidden:YES];
_toolBar.hidden = YES;
_naviBar.hidden = YES;
[_playButton setImage:nil forState:UIControlStateNormal];
[UIApplication sharedApplication].statusBarHidden = YES;
} else {
......@@ -285,7 +312,8 @@
- (void)pausePlayerAndShowNaviBar {
[_player pause];
_toolBar.hidden = NO;
[self.navigationController setNavigationBarHidden:NO];
_naviBar.hidden = NO;
[self.navigationController setNavigationBarHidden:YES];
[_playButton setImage:[UIImage tz_imageNamedFromMyBundle:@"MMVideoPreviewPlay"] forState:UIControlStateNormal];
if (self.needShowStatusBar) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment