Commit 316b5ef2 authored by shuijing's avatar shuijing

【feat】图片选择器 ui重构

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