Commit 452babd8 authored by yuzheng.tz's avatar yuzheng.tz

新增是否显示图片选中序号的属性

parent 7fa5ea76
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" ambiguous="YES" keyboardDismissMode="onDrag" translatesAutoresizingMaskIntoConstraints="NO" id="AMD-xf-cz2"> <scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" ambiguous="YES" keyboardDismissMode="onDrag" translatesAutoresizingMaskIntoConstraints="NO" id="AMD-xf-cz2">
<rect key="frame" x="0.0" y="0.0" width="375" height="440"/> <rect key="frame" x="0.0" y="0.0" width="375" height="640"/>
<subviews> <subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="obE-hs-XLa" userLabel="View1"> <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="obE-hs-XLa" userLabel="View1">
<rect key="frame" x="0.0" y="20" width="375" height="35"/> <rect key="frame" x="0.0" y="20" width="375" height="35"/>
...@@ -283,6 +283,24 @@ ...@@ -283,6 +283,24 @@
</subviews> </subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view> </view>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="fWM-jc-1VU" userLabel="View14">
<rect key="frame" x="0.0" y="475" width="375" height="35"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="XsY-NI-Txd">
<rect key="frame" x="225" y="2" width="51" height="31"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</switch>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="右上角显示图片选中序号" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="nm2-mT-siy">
<rect key="frame" x="0.0" y="0.0" width="200" height="35"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
</subviews> </subviews>
<constraints> <constraints>
<constraint firstItem="VUP-wm-Ah2" firstAttribute="leading" secondItem="PA2-zk-4Ey" secondAttribute="leading" id="1iv-97-UAf"/> <constraint firstItem="VUP-wm-Ah2" firstAttribute="leading" secondItem="PA2-zk-4Ey" secondAttribute="leading" id="1iv-97-UAf"/>
...@@ -360,6 +378,7 @@ ...@@ -360,6 +378,7 @@
<outlet property="maxCountTF" destination="37K-cO-hgf" id="776-gE-tea"/> <outlet property="maxCountTF" destination="37K-cO-hgf" id="776-gE-tea"/>
<outlet property="needCircleCropSwitch" destination="hsH-wt-l1R" id="SVP-EE-wgf"/> <outlet property="needCircleCropSwitch" destination="hsH-wt-l1R" id="SVP-EE-wgf"/>
<outlet property="scrollView" destination="AMD-xf-cz2" id="0Bb-Te-K4h"/> <outlet property="scrollView" destination="AMD-xf-cz2" id="0Bb-Te-K4h"/>
<outlet property="showSelectedIndexSwitch" destination="XsY-NI-Txd" id="ou9-YO-ebP"/>
<outlet property="showSheetSwitch" destination="uHt-bT-lBZ" id="NxK-wM-ivE"/> <outlet property="showSheetSwitch" destination="uHt-bT-lBZ" id="NxK-wM-ivE"/>
<outlet property="showTakePhotoBtnSwitch" destination="jpa-B9-8n6" id="lh8-2O-IWS"/> <outlet property="showTakePhotoBtnSwitch" destination="jpa-B9-8n6" id="lh8-2O-IWS"/>
<outlet property="showTakeVideoBtnSwitch" destination="mMy-bi-cIJ" id="jER-Fp-aOr"/> <outlet property="showTakeVideoBtnSwitch" destination="mMy-bi-cIJ" id="jER-Fp-aOr"/>
......
...@@ -22,6 +22,7 @@ typedef enum : NSUInteger { ...@@ -22,6 +22,7 @@ typedef enum : NSUInteger {
@property (weak, nonatomic) UIButton *selectPhotoButton; @property (weak, nonatomic) UIButton *selectPhotoButton;
@property (nonatomic, strong) TZAssetModel *model; @property (nonatomic, strong) TZAssetModel *model;
@property (assign, nonatomic) NSInteger index;
@property (nonatomic, copy) void (^didSelectPhotoBlock)(BOOL); @property (nonatomic, copy) void (^didSelectPhotoBlock)(BOOL);
@property (nonatomic, assign) TZAssetCellType type; @property (nonatomic, assign) TZAssetCellType type;
@property (nonatomic, assign) BOOL allowPickingGif; @property (nonatomic, assign) BOOL allowPickingGif;
...@@ -29,12 +30,12 @@ typedef enum : NSUInteger { ...@@ -29,12 +30,12 @@ typedef enum : NSUInteger {
@property (nonatomic, copy) NSString *representedAssetIdentifier; @property (nonatomic, copy) NSString *representedAssetIdentifier;
@property (nonatomic, assign) int32_t imageRequestID; @property (nonatomic, assign) int32_t imageRequestID;
@property (nonatomic, copy) NSString *photoSelImageName; @property (nonatomic, strong) UIImage *photoSelImage;
@property (nonatomic, copy) NSString *photoDefImageName; @property (nonatomic, strong) UIImage *photoDefImage;
@property (nonatomic, assign) BOOL showSelectBtn; @property (nonatomic, assign) BOOL showSelectBtn;
@property (assign, nonatomic) BOOL allowPreview; @property (assign, nonatomic) BOOL allowPreview;
@property (assign, nonatomic) BOOL useCachedImage;
@end @end
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
@interface TZAssetCell () @interface TZAssetCell ()
@property (weak, nonatomic) UIImageView *imageView; // The photo / 照片 @property (weak, nonatomic) UIImageView *imageView; // The photo / 照片
@property (weak, nonatomic) UIImageView *selectImageView; @property (weak, nonatomic) UIImageView *selectImageView;
@property (weak, nonatomic) UILabel *indexLabel;
@property (weak, nonatomic) UIView *bottomView; @property (weak, nonatomic) UIView *bottomView;
@property (weak, nonatomic) UILabel *timeLength; @property (weak, nonatomic) UILabel *timeLength;
...@@ -31,6 +32,9 @@ ...@@ -31,6 +32,9 @@
if (iOS8Later) { if (iOS8Later) {
self.representedAssetIdentifier = [[TZImageManager manager] getAssetIdentifier:model.asset]; self.representedAssetIdentifier = [[TZImageManager manager] getAssetIdentifier:model.asset];
} }
if (self.useCachedImage && model.cachedImage) {
self.imageView.image = model.cachedImage;
} else {
int32_t imageRequestID = [[TZImageManager manager] getPhotoWithAsset:model.asset photoWidth:self.tz_width completion:^(UIImage *photo, NSDictionary *info, BOOL isDegraded) { int32_t imageRequestID = [[TZImageManager manager] getPhotoWithAsset:model.asset photoWidth:self.tz_width completion:^(UIImage *photo, NSDictionary *info, BOOL isDegraded) {
if (self->_progressView) { if (self->_progressView) {
self.progressView.hidden = YES; self.progressView.hidden = YES;
...@@ -49,14 +53,18 @@ ...@@ -49,14 +53,18 @@
if (!isDegraded) { if (!isDegraded) {
self.imageRequestID = 0; self.imageRequestID = 0;
} }
self.model.cachedImage = photo;
} progressHandler:nil networkAccessAllowed:NO]; } progressHandler:nil networkAccessAllowed:NO];
if (imageRequestID && self.imageRequestID && imageRequestID != self.imageRequestID) { if (imageRequestID && self.imageRequestID && imageRequestID != self.imageRequestID) {
[[PHImageManager defaultManager] cancelImageRequest:self.imageRequestID]; [[PHImageManager defaultManager] cancelImageRequest:self.imageRequestID];
// NSLog(@"cancelImageRequest %d",self.imageRequestID); // NSLog(@"cancelImageRequest %d",self.imageRequestID);
} }
self.imageRequestID = imageRequestID; self.imageRequestID = imageRequestID;
}
self.selectPhotoButton.selected = model.isSelected; self.selectPhotoButton.selected = model.isSelected;
self.selectImageView.image = self.selectPhotoButton.isSelected ? [UIImage imageNamedFromMyBundle:self.photoSelImageName] : [UIImage imageNamedFromMyBundle:self.photoDefImageName]; self.selectImageView.image = self.selectPhotoButton.isSelected ? self.photoSelImage : self.photoDefImage;
self.indexLabel.hidden = !self.selectPhotoButton.isSelected;
self.type = (NSInteger)model.type; self.type = (NSInteger)model.type;
// 让宽度/高度小于 最小可选照片尺寸 的图片不能选中 // 让宽度/高度小于 最小可选照片尺寸 的图片不能选中
if (![[TZImageManager manager] isPhotoSelectableWithAsset:model.asset]) { if (![[TZImageManager manager] isPhotoSelectableWithAsset:model.asset]) {
...@@ -69,9 +77,19 @@ ...@@ -69,9 +77,19 @@
if (model.isSelected) { if (model.isSelected) {
[self fetchBigImage]; [self fetchBigImage];
} }
if (model.needOscillatoryAnimation) {
[UIView showOscillatoryAnimationWithLayer:self.selectImageView.layer type:TZOscillatoryAnimationToBigger];
model.needOscillatoryAnimation = NO;
}
[self setNeedsLayout]; [self setNeedsLayout];
} }
- (void)setIndex:(NSInteger)index {
_index = index;
self.indexLabel.text = [NSString stringWithFormat:@"%zd", index];
[self.contentView bringSubviewToFront:self.indexLabel];
}
- (void)setShowSelectBtn:(BOOL)showSelectBtn { - (void)setShowSelectBtn:(BOOL)showSelectBtn {
_showSelectBtn = showSelectBtn; _showSelectBtn = showSelectBtn;
if (!self.selectPhotoButton.hidden) { if (!self.selectPhotoButton.hidden) {
...@@ -112,9 +130,11 @@ ...@@ -112,9 +130,11 @@
if (self.didSelectPhotoBlock) { if (self.didSelectPhotoBlock) {
self.didSelectPhotoBlock(sender.isSelected); self.didSelectPhotoBlock(sender.isSelected);
} }
self.selectImageView.image = sender.isSelected ? [UIImage imageNamedFromMyBundle:self.photoSelImageName] : [UIImage imageNamedFromMyBundle:self.photoDefImageName]; self.selectImageView.image = sender.isSelected ? self.photoSelImage : self.photoDefImage;
if (sender.isSelected) { if (sender.isSelected) {
if (![TZImagePickerConfig sharedInstance].showSelectedIndex) {
[UIView showOscillatoryAnimationWithLayer:_selectImageView.layer type:TZOscillatoryAnimationToBigger]; [UIView showOscillatoryAnimationWithLayer:_selectImageView.layer type:TZOscillatoryAnimationToBigger];
}
// 用户选中了该图片,提前获取一下大图 // 用户选中了该图片,提前获取一下大图
[self fetchBigImage]; [self fetchBigImage];
} else { // 取消选中,取消大图的获取 } else { // 取消选中,取消大图的获取
...@@ -180,6 +200,8 @@ ...@@ -180,6 +200,8 @@
- (UIImageView *)selectImageView { - (UIImageView *)selectImageView {
if (_selectImageView == nil) { if (_selectImageView == nil) {
UIImageView *selectImageView = [[UIImageView alloc] init]; UIImageView *selectImageView = [[UIImageView alloc] init];
selectImageView.contentMode = UIViewContentModeCenter;
selectImageView.clipsToBounds = YES;
[self.contentView addSubview:selectImageView]; [self.contentView addSubview:selectImageView];
_selectImageView = selectImageView; _selectImageView = selectImageView;
} }
...@@ -219,6 +241,18 @@ ...@@ -219,6 +241,18 @@
return _timeLength; return _timeLength;
} }
- (UILabel *)indexLabel {
if (_indexLabel == nil) {
UILabel *indexLabel = [[UILabel alloc] init];
indexLabel.font = [UIFont systemFontOfSize:14];
indexLabel.textColor = [UIColor whiteColor];
indexLabel.textAlignment = NSTextAlignmentCenter;
[self.contentView addSubview:indexLabel];
_indexLabel = indexLabel;
}
return _indexLabel;
}
- (TZProgressView *)progressView { - (TZProgressView *)progressView {
if (_progressView == nil) { if (_progressView == nil) {
_progressView = [[TZProgressView alloc] init]; _progressView = [[TZProgressView alloc] init];
...@@ -235,7 +269,13 @@ ...@@ -235,7 +269,13 @@
} else { } else {
_selectPhotoButton.frame = self.bounds; _selectPhotoButton.frame = self.bounds;
} }
_selectImageView.frame = CGRectMake(self.tz_width - 27, 0, 27, 27); _selectImageView.frame = CGRectMake(self.tz_width - 27, 3, 24, 24);
if (_selectImageView.image.size.width <= 27) {
_selectImageView.contentMode = UIViewContentModeCenter;
} else {
_selectImageView.contentMode = UIViewContentModeScaleAspectFit;
}
_indexLabel.frame = _selectImageView.frame;
_imageView.frame = CGRectMake(0, 0, self.tz_width, self.tz_height); _imageView.frame = CGRectMake(0, 0, self.tz_width, self.tz_height);
static CGFloat progressWH = 20; static CGFloat progressWH = 20;
......
...@@ -23,7 +23,9 @@ typedef enum : NSUInteger { ...@@ -23,7 +23,9 @@ typedef enum : NSUInteger {
@property (nonatomic, strong) id asset; ///< PHAsset or ALAsset @property (nonatomic, strong) id asset; ///< PHAsset or ALAsset
@property (nonatomic, assign) BOOL isSelected; ///< The select status of a photo, default is No @property (nonatomic, assign) BOOL isSelected; ///< The select status of a photo, default is No
@property (nonatomic, assign) TZAssetModelMediaType type; @property (nonatomic, assign) TZAssetModelMediaType type;
@property (assign, nonatomic) BOOL needOscillatoryAnimation;
@property (nonatomic, copy) NSString *timeLength; @property (nonatomic, copy) NSString *timeLength;
@property (strong, nonatomic) UIImage *cachedImage;
/// Init a photo dataModel With a asset /// Init a photo dataModel With a asset
/// 用一个PHAsset/ALAsset实例,初始化一个照片模型 /// 用一个PHAsset/ALAsset实例,初始化一个照片模型
......
...@@ -114,14 +114,21 @@ ...@@ -114,14 +114,21 @@
/// 默认为YES,如果设置为NO, 选择器将不会自己dismiss /// 默认为YES,如果设置为NO, 选择器将不会自己dismiss
@property(nonatomic, assign) BOOL autoDismiss; @property(nonatomic, assign) BOOL autoDismiss;
/// Default is YES, if set NO, in the delegate method the photos and infos will be nil, only assets hava value. /// Default is NO, if set YES, in the delegate method the photos and infos will be nil, only assets hava value.
/// 默认为NO,如果设置为YES,代理方法里photos和infos会是nil,只返回assets /// 默认为NO,如果设置为YES,代理方法里photos和infos会是nil,只返回assets
@property (assign, nonatomic) BOOL onlyReturnAsset; @property (assign, nonatomic) BOOL onlyReturnAsset;
/// Default is NO, if set YES, will show the image's selected index.
/// 默认为NO,如果设置为YES,会显示照片的选中序号
@property (assign, nonatomic) BOOL showSelectedIndex;
/// The photos user have selected /// The photos user have selected
/// 用户选中过的图片数组 /// 用户选中过的图片数组
@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;
- (void)addSelectedModel:(TZAssetModel *)model;
- (void)removeSelectedModel:(TZAssetModel *)model;
/// Minimum selectable photo width, Default is 0 /// Minimum selectable photo width, Default is 0
/// 最小可选中的图片宽度,默认是0,小于这个宽度的图片不可选中 /// 最小可选中的图片宽度,默认是0,小于这个宽度的图片不可选中
...@@ -158,13 +165,20 @@ ...@@ -158,13 +165,20 @@
@property (assign, nonatomic) BOOL needShowStatusBar; @property (assign, nonatomic) BOOL needShowStatusBar;
#pragma mark - #pragma mark -
@property (nonatomic, copy) NSString *takePictureImageName; @property (nonatomic, copy) NSString *takePictureImageName __attribute__((deprecated("Use -takePictureImage.")));
@property (nonatomic, copy) NSString *photoSelImageName; @property (nonatomic, copy) NSString *photoSelImageName __attribute__((deprecated("Use -photoSelImage.")));
@property (nonatomic, copy) NSString *photoDefImageName; @property (nonatomic, copy) NSString *photoDefImageName __attribute__((deprecated("Use -photoDefImage.")));
@property (nonatomic, copy) NSString *photoOriginSelImageName; @property (nonatomic, copy) NSString *photoOriginSelImageName __attribute__((deprecated("Use -photoOriginSelImage.")));
@property (nonatomic, copy) NSString *photoOriginDefImageName; @property (nonatomic, copy) NSString *photoOriginDefImageName __attribute__((deprecated("Use -photoOriginDefImage.")));
@property (nonatomic, copy) NSString *photoPreviewOriginDefImageName; @property (nonatomic, copy) NSString *photoPreviewOriginDefImageName __attribute__((deprecated("Use -photoPreviewOriginDefImage.")));
@property (nonatomic, copy) NSString *photoNumberIconImageName; @property (nonatomic, copy) NSString *photoNumberIconImageName __attribute__((deprecated("Use -photoNumberIconImage.")));
@property (nonatomic, strong) UIImage *takePictureImage;
@property (nonatomic, strong) UIImage *photoSelImage;
@property (nonatomic, strong) UIImage *photoDefImage;
@property (nonatomic, strong) UIImage *photoOriginSelImage;
@property (nonatomic, strong) UIImage *photoOriginDefImage;
@property (nonatomic, strong) UIImage *photoPreviewOriginDefImage;
@property (nonatomic, strong) UIImage *photoNumberIconImage;
#pragma mark - #pragma mark -
/// Appearance / 外观颜色 + 按钮文字 /// Appearance / 外观颜色 + 按钮文字
...@@ -183,6 +197,10 @@ ...@@ -183,6 +197,10 @@
@property (nonatomic, copy) NSString *settingBtnTitleStr; @property (nonatomic, copy) NSString *settingBtnTitleStr;
@property (nonatomic, copy) NSString *processHintStr; @property (nonatomic, copy) NSString *processHintStr;
/// 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
/// icon主题色,默认是微信的绿色,值是r:31 g:185 b:34。目前仅支持showSelectedIndex为YES时的图片选中icon
@property (strong, nonatomic) UIColor *iconThemeColor;
#pragma mark - #pragma mark -
- (void)cancelButtonClick; - (void)cancelButtonClick;
...@@ -286,4 +304,5 @@ ...@@ -286,4 +304,5 @@
@property (strong, nonatomic) NSBundle *languageBundle; @property (strong, nonatomic) NSBundle *languageBundle;
/// 默认是200,如果一个GIF过大,里面图片个数可能超过1000,会导致内存飙升而崩溃 /// 默认是200,如果一个GIF过大,里面图片个数可能超过1000,会导致内存飙升而崩溃
@property (assign, nonatomic) NSInteger gifPreviewMaxImagesCount; @property (assign, nonatomic) NSInteger gifPreviewMaxImagesCount;
@property (assign, nonatomic) BOOL showSelectedIndex;
@end @end
...@@ -278,7 +278,7 @@ ...@@ -278,7 +278,7 @@
self.allowPreview = YES; self.allowPreview = YES;
self.statusBarStyle = UIStatusBarStyleLightContent; self.statusBarStyle = UIStatusBarStyleLightContent;
[self configDefaultImageName]; self.iconThemeColor = [UIColor colorWithRed:31 / 255.0 green:185 / 255.0 blue:34 / 255.0 alpha:1.0];
[self configDefaultBtnTitle]; [self configDefaultBtnTitle];
CGFloat cropViewWH = MIN(self.view.tz_width, self.view.tz_height) / 3 * 2; CGFloat cropViewWH = MIN(self.view.tz_width, self.view.tz_height) / 3 * 2;
...@@ -289,12 +289,52 @@ ...@@ -289,12 +289,52 @@
self.takePictureImageName = @"takePicture80"; self.takePictureImageName = @"takePicture80";
self.photoSelImageName = @"photo_sel_photoPickerVc"; self.photoSelImageName = @"photo_sel_photoPickerVc";
self.photoDefImageName = @"photo_def_photoPickerVc"; self.photoDefImageName = @"photo_def_photoPickerVc";
self.photoNumberIconImageName = @"photo_number_icon"; self.photoNumberIconImage = [self createImageWithColor:nil size:CGSizeMake(48, 48) radius:24]; // @"photo_number_icon";
self.photoPreviewOriginDefImageName = @"preview_original_def"; self.photoPreviewOriginDefImageName = @"preview_original_def";
self.photoOriginDefImageName = @"photo_original_def"; self.photoOriginDefImageName = @"photo_original_def";
self.photoOriginSelImageName = @"photo_original_sel"; self.photoOriginSelImageName = @"photo_original_sel";
} }
- (void)setTakePictureImageName:(NSString *)takePictureImageName {
_takePictureImageName = takePictureImageName;
_takePictureImage = [UIImage imageNamedFromMyBundle:takePictureImageName];
}
- (void)setPhotoSelImageName:(NSString *)photoSelImageName {
_photoSelImageName = photoSelImageName;
_photoSelImage = [UIImage imageNamedFromMyBundle:photoSelImageName];
}
- (void)setPhotoDefImageName:(NSString *)photoDefImageName {
_photoDefImageName = photoDefImageName;
_photoDefImage = [UIImage imageNamedFromMyBundle:photoDefImageName];
}
- (void)setPhotoNumberIconImageName:(NSString *)photoNumberIconImageName {
_photoNumberIconImageName = photoNumberIconImageName;
_photoNumberIconImage = [UIImage imageNamedFromMyBundle:photoNumberIconImageName];
}
- (void)setPhotoPreviewOriginDefImageName:(NSString *)photoPreviewOriginDefImageName {
_photoPreviewOriginDefImageName = photoPreviewOriginDefImageName;
_photoPreviewOriginDefImage = [UIImage imageNamedFromMyBundle:photoPreviewOriginDefImageName];
}
- (void)setPhotoOriginDefImageName:(NSString *)photoOriginDefImageName {
_photoOriginDefImageName = photoOriginDefImageName;
_photoOriginDefImage = [UIImage imageNamedFromMyBundle:photoOriginDefImageName];
}
- (void)setPhotoOriginSelImageName:(NSString *)photoOriginSelImageName {
_photoOriginSelImageName = photoOriginSelImageName;
_photoOriginSelImage = [UIImage imageNamedFromMyBundle:photoOriginSelImageName];
}
- (void)setIconThemeColor:(UIColor *)iconThemeColor {
_iconThemeColor = iconThemeColor;
[self configDefaultImageName];
}
- (void)configDefaultBtnTitle { - (void)configDefaultBtnTitle {
self.doneBtnTitleStr = [NSBundle tz_localizedStringForKey:@"Done"]; self.doneBtnTitleStr = [NSBundle tz_localizedStringForKey:@"Done"];
self.cancelBtnTitleStr = [NSBundle tz_localizedStringForKey:@"Cancel"]; self.cancelBtnTitleStr = [NSBundle tz_localizedStringForKey:@"Cancel"];
...@@ -304,6 +344,14 @@ ...@@ -304,6 +344,14 @@
self.processHintStr = [NSBundle tz_localizedStringForKey:@"Processing..."]; self.processHintStr = [NSBundle tz_localizedStringForKey:@"Processing..."];
} }
- (void)setShowSelectedIndex:(BOOL)showSelectedIndex {
_showSelectedIndex = showSelectedIndex;
if (showSelectedIndex) {
self.photoSelImage = [self createImageWithColor:nil size:CGSizeMake(48, 48) radius:24];
}
[TZImagePickerConfig sharedInstance].showSelectedIndex = showSelectedIndex;
}
- (void)observeAuthrizationStatusChange { - (void)observeAuthrizationStatusChange {
[_timer invalidate]; [_timer invalidate];
_timer = nil; _timer = nil;
...@@ -500,10 +548,11 @@ ...@@ -500,10 +548,11 @@
- (void)setSelectedAssets:(NSMutableArray *)selectedAssets { - (void)setSelectedAssets:(NSMutableArray *)selectedAssets {
_selectedAssets = selectedAssets; _selectedAssets = selectedAssets;
_selectedModels = [NSMutableArray array]; _selectedModels = [NSMutableArray array];
_selectedAssetIds = [NSMutableArray array];
for (id asset in selectedAssets) { for (id asset in selectedAssets) {
TZAssetModel *model = [TZAssetModel modelWithAsset:asset type:[[TZImageManager manager] getAssetType:asset]]; TZAssetModel *model = [TZAssetModel modelWithAsset:asset type:[[TZImageManager manager] getAssetType:asset]];
model.isSelected = YES; model.isSelected = YES;
[_selectedModels addObject:model]; [self addSelectedModel:model];
} }
} }
...@@ -555,6 +604,34 @@ ...@@ -555,6 +604,34 @@
// NSLog(@"%@ dealloc",NSStringFromClass(self.class)); // NSLog(@"%@ dealloc",NSStringFromClass(self.class));
} }
- (void)addSelectedModel:(TZAssetModel *)model {
[_selectedModels addObject:model];
NSString *assetId = [[TZImageManager manager] getAssetIdentifier:model.asset];
[_selectedAssetIds addObject:assetId];
}
- (void)removeSelectedModel:(TZAssetModel *)model {
[_selectedModels removeObject:model];
NSString *assetId = [[TZImageManager manager] getAssetIdentifier:model.asset];
[_selectedAssetIds removeObject:assetId];
}
- (UIImage *)createImageWithColor:(UIColor *)color size:(CGSize)size radius:(CGFloat)radius {
if (!color) {
color = self.iconThemeColor;
}
CGRect rect = CGRectMake(0.0f, 0.0f, size.width, size.height);
UIGraphicsBeginImageContextWithOptions(rect.size, NO, [UIScreen mainScreen].scale);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:radius];
CGContextAddPath(context, path.CGPath);
CGContextFillPath(context);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
#pragma mark - UIContentContainer #pragma mark - UIContentContainer
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator { - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
...@@ -724,7 +801,7 @@ ...@@ -724,7 +801,7 @@
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
TZAlbumCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TZAlbumCell"]; TZAlbumCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TZAlbumCell"];
TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController; TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController;
cell.selectedCountButton.backgroundColor = imagePickerVc.oKButtonTitleColorNormal; cell.selectedCountButton.backgroundColor = imagePickerVc.iconThemeColor;
cell.model = _albumArr[indexPath.row]; cell.model = _albumArr[indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell; return cell;
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
@property (strong, nonatomic) UICollectionViewFlowLayout *layout; @property (strong, nonatomic) UICollectionViewFlowLayout *layout;
@property (nonatomic, strong) UIImagePickerController *imagePickerVc; @property (nonatomic, strong) UIImagePickerController *imagePickerVc;
@property (strong, nonatomic) CLLocation *location; @property (strong, nonatomic) CLLocation *location;
@property (assign, nonatomic) BOOL useCachedImage;
@end @end
static CGSize AssetGridThumbnailSize; static CGSize AssetGridThumbnailSize;
...@@ -210,8 +211,10 @@ static CGFloat itemMargin = 5; ...@@ -210,8 +211,10 @@ static CGFloat itemMargin = 5;
[_originalPhotoButton setTitle:tzImagePickerVc.fullImageBtnTitleStr forState:UIControlStateSelected]; [_originalPhotoButton setTitle:tzImagePickerVc.fullImageBtnTitleStr forState:UIControlStateSelected];
[_originalPhotoButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal]; [_originalPhotoButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
[_originalPhotoButton setTitleColor:[UIColor blackColor] forState:UIControlStateSelected]; [_originalPhotoButton setTitleColor:[UIColor blackColor] forState:UIControlStateSelected];
[_originalPhotoButton setImage:[UIImage imageNamedFromMyBundle:tzImagePickerVc.photoOriginDefImageName] forState:UIControlStateNormal]; [_originalPhotoButton setImage:tzImagePickerVc.photoOriginDefImage forState:UIControlStateNormal];
[_originalPhotoButton setImage:[UIImage imageNamedFromMyBundle:tzImagePickerVc.photoOriginSelImageName] forState:UIControlStateSelected]; [_originalPhotoButton setImage:tzImagePickerVc.photoOriginSelImage forState:UIControlStateSelected];
_originalPhotoButton.imageView.clipsToBounds = YES;
_originalPhotoButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
_originalPhotoButton.selected = _isSelectOriginalPhoto; _originalPhotoButton.selected = _isSelectOriginalPhoto;
_originalPhotoButton.enabled = tzImagePickerVc.selectedModels.count > 0; _originalPhotoButton.enabled = tzImagePickerVc.selectedModels.count > 0;
...@@ -231,8 +234,10 @@ static CGFloat itemMargin = 5; ...@@ -231,8 +234,10 @@ static CGFloat itemMargin = 5;
[_doneButton setTitleColor:tzImagePickerVc.oKButtonTitleColorDisabled forState:UIControlStateDisabled]; [_doneButton setTitleColor:tzImagePickerVc.oKButtonTitleColorDisabled forState:UIControlStateDisabled];
_doneButton.enabled = tzImagePickerVc.selectedModels.count || tzImagePickerVc.alwaysEnableDoneBtn; _doneButton.enabled = tzImagePickerVc.selectedModels.count || tzImagePickerVc.alwaysEnableDoneBtn;
_numberImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamedFromMyBundle:tzImagePickerVc.photoNumberIconImageName]]; _numberImageView = [[UIImageView alloc] initWithImage:tzImagePickerVc.photoNumberIconImage];
_numberImageView.hidden = tzImagePickerVc.selectedModels.count <= 0; _numberImageView.hidden = tzImagePickerVc.selectedModels.count <= 0;
_numberImageView.clipsToBounds = YES;
_numberImageView.contentMode = UIViewContentModeScaleAspectFit;
_numberImageView.backgroundColor = [UIColor clearColor]; _numberImageView.backgroundColor = [UIColor clearColor];
_numberLabel = [[UILabel alloc] init]; _numberLabel = [[UILabel alloc] init];
...@@ -308,8 +313,8 @@ static CGFloat itemMargin = 5; ...@@ -308,8 +313,8 @@ static CGFloat itemMargin = 5;
_originalPhotoLabel.frame = CGRectMake(fullImageWidth + 46, 0, 80, 50); _originalPhotoLabel.frame = CGRectMake(fullImageWidth + 46, 0, 80, 50);
} }
[_doneButton sizeToFit]; [_doneButton sizeToFit];
_doneButton.frame = CGRectMake(self.view.tz_width - _doneButton.tz_width - 12, 0, _doneButton.tz_width, 44); _doneButton.frame = CGRectMake(self.view.tz_width - _doneButton.tz_width - 12, 0, _doneButton.tz_width, 50);
_numberImageView.frame = CGRectMake(_doneButton.tz_left - 30 - 2, 7, 30, 30); _numberImageView.frame = CGRectMake(_doneButton.tz_left - 24 - 5, 13, 24, 24);
_numberLabel.frame = _numberImageView.frame; _numberLabel.frame = _numberImageView.frame;
_divideLine.frame = CGRectMake(0, 0, self.view.tz_width, 1); _divideLine.frame = CGRectMake(0, 0, self.view.tz_width, 1);
...@@ -456,7 +461,7 @@ static CGFloat itemMargin = 5; ...@@ -456,7 +461,7 @@ static CGFloat itemMargin = 5;
TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController; TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
if (((tzImagePickerVc.sortAscendingByModificationDate && indexPath.row >= _models.count) || (!tzImagePickerVc.sortAscendingByModificationDate && indexPath.row == 0)) && _showTakePhotoBtn) { if (((tzImagePickerVc.sortAscendingByModificationDate && indexPath.row >= _models.count) || (!tzImagePickerVc.sortAscendingByModificationDate && indexPath.row == 0)) && _showTakePhotoBtn) {
TZAssetCameraCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TZAssetCameraCell" forIndexPath:indexPath]; TZAssetCameraCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TZAssetCameraCell" forIndexPath:indexPath];
cell.imageView.image = [UIImage imageNamedFromMyBundle:tzImagePickerVc.takePictureImageName]; cell.imageView.image = tzImagePickerVc.takePictureImage;
if ([tzImagePickerVc.takePictureImageName isEqualToString:@"takePicture80"]) { if ([tzImagePickerVc.takePictureImageName isEqualToString:@"takePicture80"]) {
cell.imageView.contentMode = UIViewContentModeCenter; cell.imageView.contentMode = UIViewContentModeCenter;
CGFloat rgb = 223 / 255.0; CGFloat rgb = 223 / 255.0;
...@@ -469,8 +474,9 @@ static CGFloat itemMargin = 5; ...@@ -469,8 +474,9 @@ static CGFloat itemMargin = 5;
// 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.allowPickingMultipleVideo = tzImagePickerVc.allowPickingMultipleVideo; cell.allowPickingMultipleVideo = tzImagePickerVc.allowPickingMultipleVideo;
cell.photoDefImageName = tzImagePickerVc.photoDefImageName; cell.photoDefImage = tzImagePickerVc.photoDefImage;
cell.photoSelImageName = tzImagePickerVc.photoSelImageName; cell.photoSelImage = tzImagePickerVc.photoSelImage;
cell.useCachedImage = self.useCachedImage;
TZAssetModel *model; TZAssetModel *model;
if (tzImagePickerVc.sortAscendingByModificationDate || !_showTakePhotoBtn) { if (tzImagePickerVc.sortAscendingByModificationDate || !_showTakePhotoBtn) {
model = _models[indexPath.row]; model = _models[indexPath.row];
...@@ -479,6 +485,10 @@ static CGFloat itemMargin = 5; ...@@ -479,6 +485,10 @@ static CGFloat itemMargin = 5;
} }
cell.allowPickingGif = tzImagePickerVc.allowPickingGif; cell.allowPickingGif = tzImagePickerVc.allowPickingGif;
cell.model = model; cell.model = model;
if (model.isSelected && tzImagePickerVc.showSelectedIndex) {
NSString *assetId = [[TZImageManager manager] getAssetIdentifier:model.asset];
cell.index = [tzImagePickerVc.selectedAssetIds indexOfObject:assetId] + 1;
}
cell.showSelectBtn = tzImagePickerVc.showSelectBtn; cell.showSelectBtn = tzImagePickerVc.showSelectBtn;
cell.allowPreview = tzImagePickerVc.allowPreview; cell.allowPreview = tzImagePickerVc.allowPreview;
...@@ -497,17 +507,24 @@ static CGFloat itemMargin = 5; ...@@ -497,17 +507,24 @@ static CGFloat itemMargin = 5;
NSArray *selectedModels = [NSArray arrayWithArray:tzImagePickerVc.selectedModels]; NSArray *selectedModels = [NSArray arrayWithArray:tzImagePickerVc.selectedModels];
for (TZAssetModel *model_item in selectedModels) { for (TZAssetModel *model_item in selectedModels) {
if ([[[TZImageManager manager] getAssetIdentifier:model.asset] isEqualToString:[[TZImageManager manager] getAssetIdentifier:model_item.asset]]) { if ([[[TZImageManager manager] getAssetIdentifier:model.asset] isEqualToString:[[TZImageManager manager] getAssetIdentifier:model_item.asset]]) {
[tzImagePickerVc.selectedModels removeObject:model_item]; [tzImagePickerVc removeSelectedModel:model_item];
break; break;
} }
} }
[strongSelf refreshBottomToolBarStatus]; [strongSelf refreshBottomToolBarStatus];
if (tzImagePickerVc.showSelectedIndex) {
[strongSelf setUseCachedImageAndReloadData];
}
} else { } else {
// 2. select:check if over the maxImagesCount / 选择照片,检查是否超过了最大个数的限制 // 2. select:check if over the maxImagesCount / 选择照片,检查是否超过了最大个数的限制
if (tzImagePickerVc.selectedModels.count < tzImagePickerVc.maxImagesCount) { if (tzImagePickerVc.selectedModels.count < tzImagePickerVc.maxImagesCount) {
strongCell.selectPhotoButton.selected = YES; strongCell.selectPhotoButton.selected = YES;
model.isSelected = YES; model.isSelected = YES;
[tzImagePickerVc.selectedModels addObject:model]; if (tzImagePickerVc.showSelectedIndex) {
model.needOscillatoryAnimation = YES;
[strongSelf setUseCachedImageAndReloadData];
}
[tzImagePickerVc addSelectedModel:model];
[strongSelf refreshBottomToolBarStatus]; [strongSelf refreshBottomToolBarStatus];
} else { } else {
NSString *title = [NSString stringWithFormat:[NSBundle tz_localizedStringForKey:@"Select a maximum of %zd photos"], tzImagePickerVc.maxImagesCount]; NSString *title = [NSString stringWithFormat:[NSBundle tz_localizedStringForKey:@"Select a maximum of %zd photos"], tzImagePickerVc.maxImagesCount];
...@@ -567,6 +584,14 @@ static CGFloat itemMargin = 5; ...@@ -567,6 +584,14 @@ static CGFloat itemMargin = 5;
#pragma mark - Private Method #pragma mark - Private Method
- (void)setUseCachedImageAndReloadData {
self.useCachedImage = YES;
[self.collectionView reloadData];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.useCachedImage = NO;
});
}
/// 拍照按钮点击事件 /// 拍照按钮点击事件
- (void)takePhoto { - (void)takePhoto {
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
...@@ -788,7 +813,7 @@ static CGFloat itemMargin = 5; ...@@ -788,7 +813,7 @@ static CGFloat itemMargin = 5;
photoPreviewVc.models = self->_models; photoPreviewVc.models = self->_models;
[self pushPhotoPrevireViewController:photoPreviewVc]; [self pushPhotoPrevireViewController:photoPreviewVc];
} else { } else {
[tzImagePickerVc.selectedModels addObject:assetModel]; [tzImagePickerVc addSelectedModel:assetModel];
[self doneButtonClick]; [self doneButtonClick];
} }
return; return;
...@@ -799,7 +824,7 @@ static CGFloat itemMargin = 5; ...@@ -799,7 +824,7 @@ static CGFloat itemMargin = 5;
// 不能多选视频的情况下,不选中拍摄的视频 // 不能多选视频的情况下,不选中拍摄的视频
} else { } else {
assetModel.isSelected = YES; assetModel.isSelected = YES;
[tzImagePickerVc.selectedModels addObject:assetModel]; [tzImagePickerVc addSelectedModel:assetModel];
[self refreshBottomToolBarStatus]; [self refreshBottomToolBarStatus];
} }
} }
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
UIView *_naviBar; UIView *_naviBar;
UIButton *_backButton; UIButton *_backButton;
UIButton *_selectButton; UIButton *_selectButton;
UILabel *_indexLabel;
UIView *_toolBar; UIView *_toolBar;
UIButton *_doneButton; UIButton *_doneButton;
...@@ -98,12 +99,21 @@ ...@@ -98,12 +99,21 @@
[_backButton addTarget:self action:@selector(backButtonClick) forControlEvents:UIControlEventTouchUpInside]; [_backButton addTarget:self action:@selector(backButtonClick) forControlEvents:UIControlEventTouchUpInside];
_selectButton = [[UIButton alloc] initWithFrame:CGRectZero]; _selectButton = [[UIButton alloc] initWithFrame:CGRectZero];
[_selectButton setImage:[UIImage imageNamedFromMyBundle:tzImagePickerVc.photoDefImageName] forState:UIControlStateNormal]; [_selectButton setImage:tzImagePickerVc.photoDefImage forState:UIControlStateNormal];
[_selectButton setImage:[UIImage imageNamedFromMyBundle:tzImagePickerVc.photoSelImageName] forState:UIControlStateSelected]; [_selectButton setImage:tzImagePickerVc.photoSelImage forState:UIControlStateSelected];
_selectButton.imageView.clipsToBounds = YES;
_selectButton.imageEdgeInsets = UIEdgeInsetsMake(10, 0, 10, 0);
_selectButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
[_selectButton addTarget:self action:@selector(select:) forControlEvents:UIControlEventTouchUpInside]; [_selectButton addTarget:self action:@selector(select:) forControlEvents:UIControlEventTouchUpInside];
_selectButton.hidden = !tzImagePickerVc.showSelectBtn; _selectButton.hidden = !tzImagePickerVc.showSelectBtn;
_indexLabel = [[UILabel alloc] init];
_indexLabel.font = [UIFont systemFontOfSize:14];
_indexLabel.textColor = [UIColor whiteColor];
_indexLabel.textAlignment = NSTextAlignmentCenter;
[_naviBar addSubview:_selectButton]; [_naviBar addSubview:_selectButton];
[_naviBar addSubview:_indexLabel];
[_naviBar addSubview:_backButton]; [_naviBar addSubview:_backButton];
[self.view addSubview:_naviBar]; [self.view addSubview:_naviBar];
} }
...@@ -124,8 +134,8 @@ ...@@ -124,8 +134,8 @@
[_originalPhotoButton setTitle:_tzImagePickerVc.fullImageBtnTitleStr forState:UIControlStateSelected]; [_originalPhotoButton setTitle:_tzImagePickerVc.fullImageBtnTitleStr forState:UIControlStateSelected];
[_originalPhotoButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal]; [_originalPhotoButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
[_originalPhotoButton setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected]; [_originalPhotoButton setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
[_originalPhotoButton setImage:[UIImage imageNamedFromMyBundle:_tzImagePickerVc.photoPreviewOriginDefImageName] forState:UIControlStateNormal]; [_originalPhotoButton setImage:_tzImagePickerVc.photoPreviewOriginDefImage forState:UIControlStateNormal];
[_originalPhotoButton setImage:[UIImage imageNamedFromMyBundle:_tzImagePickerVc.photoOriginSelImageName] forState:UIControlStateSelected]; [_originalPhotoButton setImage:_tzImagePickerVc.photoOriginSelImage forState:UIControlStateSelected];
_originalPhotoLabel = [[UILabel alloc] init]; _originalPhotoLabel = [[UILabel alloc] init];
_originalPhotoLabel.textAlignment = NSTextAlignmentLeft; _originalPhotoLabel.textAlignment = NSTextAlignmentLeft;
...@@ -141,8 +151,10 @@ ...@@ -141,8 +151,10 @@
[_doneButton setTitle:_tzImagePickerVc.doneBtnTitleStr forState:UIControlStateNormal]; [_doneButton setTitle:_tzImagePickerVc.doneBtnTitleStr forState:UIControlStateNormal];
[_doneButton setTitleColor:_tzImagePickerVc.oKButtonTitleColorNormal forState:UIControlStateNormal]; [_doneButton setTitleColor:_tzImagePickerVc.oKButtonTitleColorNormal forState:UIControlStateNormal];
_numberImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamedFromMyBundle:_tzImagePickerVc.photoNumberIconImageName]]; _numberImageView = [[UIImageView alloc] initWithImage:_tzImagePickerVc.photoNumberIconImage];
_numberImageView.backgroundColor = [UIColor clearColor]; _numberImageView.backgroundColor = [UIColor clearColor];
_numberImageView.clipsToBounds = YES;
_numberImageView.contentMode = UIViewContentModeScaleAspectFit;
_numberImageView.hidden = _tzImagePickerVc.selectedModels.count <= 0; _numberImageView.hidden = _tzImagePickerVc.selectedModels.count <= 0;
_numberLabel = [[UILabel alloc] init]; _numberLabel = [[UILabel alloc] init];
...@@ -223,7 +235,8 @@ ...@@ -223,7 +235,8 @@
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);
_selectButton.frame = CGRectMake(self.view.tz_width - 54, 10 + statusBarHeightInterval, 42, 42); _selectButton.frame = CGRectMake(self.view.tz_width - 56, 10 + statusBarHeightInterval, 44, 44);
_indexLabel.frame = _selectButton.frame;
_layout.itemSize = CGSizeMake(self.view.tz_width + 20, self.view.tz_height); _layout.itemSize = CGSizeMake(self.view.tz_width + 20, self.view.tz_height);
_layout.minimumInteritemSpacing = 0; _layout.minimumInteritemSpacing = 0;
...@@ -248,7 +261,7 @@ ...@@ -248,7 +261,7 @@
} }
[_doneButton sizeToFit]; [_doneButton sizeToFit];
_doneButton.frame = CGRectMake(self.view.tz_width - _doneButton.tz_width - 12, 0, _doneButton.tz_width, 44); _doneButton.frame = CGRectMake(self.view.tz_width - _doneButton.tz_width - 12, 0, _doneButton.tz_width, 44);
_numberImageView.frame = CGRectMake(_doneButton.tz_left - 30 - 2, 7, 30, 30); _numberImageView.frame = CGRectMake(_doneButton.tz_left - 24 - 5, 10, 24, 24);
_numberLabel.frame = _numberImageView.frame; _numberLabel.frame = _numberImageView.frame;
[self configCropView]; [self configCropView];
...@@ -273,7 +286,7 @@ ...@@ -273,7 +286,7 @@
return; return;
// 2. if not over the maxImagesCount / 如果没有超过最大个数限制 // 2. if not over the maxImagesCount / 如果没有超过最大个数限制
} else { } else {
[_tzImagePickerVc.selectedModels addObject:model]; [_tzImagePickerVc addSelectedModel:model];
if (self.photos) { if (self.photos) {
[_tzImagePickerVc.selectedAssets addObject:_assetsTemp[_currentIndex]]; [_tzImagePickerVc.selectedAssets addObject:_assetsTemp[_currentIndex]];
[self.photos addObject:_photosTemp[_currentIndex]]; [self.photos addObject:_photosTemp[_currentIndex]];
...@@ -291,11 +304,11 @@ ...@@ -291,11 +304,11 @@
for (NSInteger i = 0; i < selectedModelsTmp.count; i++) { for (NSInteger i = 0; i < selectedModelsTmp.count; i++) {
TZAssetModel *model = selectedModelsTmp[i]; TZAssetModel *model = selectedModelsTmp[i];
if ([model isEqual:model_item]) { if ([model isEqual:model_item]) {
[_tzImagePickerVc.selectedModels removeObjectAtIndex:i]; [_tzImagePickerVc removeSelectedModel:model];
// [_tzImagePickerVc.selectedModels removeObjectAtIndex:i];
break; break;
} }
} }
// [_tzImagePickerVc.selectedModels removeObject:model_item];
if (self.photos) { if (self.photos) {
// 1.6.7版本更新:防止有多个一样的asset,一次性被移除了 // 1.6.7版本更新:防止有多个一样的asset,一次性被移除了
NSArray *selectedAssetsTmp = [NSArray arrayWithArray:_tzImagePickerVc.selectedAssets]; NSArray *selectedAssetsTmp = [NSArray arrayWithArray:_tzImagePickerVc.selectedAssets];
...@@ -343,7 +356,7 @@ ...@@ -343,7 +356,7 @@
// 如果没有选中过照片 点击确定时选中当前预览的照片 // 如果没有选中过照片 点击确定时选中当前预览的照片
if (_tzImagePickerVc.selectedModels.count == 0 && _tzImagePickerVc.minImagesCount <= 0) { if (_tzImagePickerVc.selectedModels.count == 0 && _tzImagePickerVc.minImagesCount <= 0) {
TZAssetModel *model = _models[_currentIndex]; TZAssetModel *model = _models[_currentIndex];
[_tzImagePickerVc.selectedModels addObject:model]; [_tzImagePickerVc addSelectedModel:model];
} }
if (_tzImagePickerVc.allowCrop) { // 裁剪状态 if (_tzImagePickerVc.allowCrop) { // 裁剪状态
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:_currentIndex inSection:0]; NSIndexPath *indexPath = [NSIndexPath indexPathForItem:_currentIndex inSection:0];
...@@ -475,6 +488,15 @@ ...@@ -475,6 +488,15 @@
TZImagePickerController *_tzImagePickerVc = (TZImagePickerController *)self.navigationController; TZImagePickerController *_tzImagePickerVc = (TZImagePickerController *)self.navigationController;
TZAssetModel *model = _models[_currentIndex]; TZAssetModel *model = _models[_currentIndex];
_selectButton.selected = model.isSelected; _selectButton.selected = model.isSelected;
[self refreshSelectButtonImageViewContentMode];
if (_selectButton.isSelected && _tzImagePickerVc.showSelectedIndex) {
NSString *assetId = [[TZImageManager manager] getAssetIdentifier:model.asset];
NSString *index = [NSString stringWithFormat:@"%zd", [_tzImagePickerVc.selectedAssetIds indexOfObject:assetId] + 1];
_indexLabel.text = index;
_indexLabel.hidden = NO;
} else {
_indexLabel.hidden = YES;
}
_numberLabel.text = [NSString stringWithFormat:@"%zd",_tzImagePickerVc.selectedModels.count]; _numberLabel.text = [NSString stringWithFormat:@"%zd",_tzImagePickerVc.selectedModels.count];
_numberImageView.hidden = (_tzImagePickerVc.selectedModels.count <= 0 || _isHideNaviBar || _isCropImage); _numberImageView.hidden = (_tzImagePickerVc.selectedModels.count <= 0 || _isHideNaviBar || _isCropImage);
_numberLabel.hidden = (_tzImagePickerVc.selectedModels.count <= 0 || _isHideNaviBar || _isCropImage); _numberLabel.hidden = (_tzImagePickerVc.selectedModels.count <= 0 || _isHideNaviBar || _isCropImage);
...@@ -508,6 +530,16 @@ ...@@ -508,6 +530,16 @@
} }
} }
- (void)refreshSelectButtonImageViewContentMode {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (self->_selectButton.imageView.image.size.width <= 27) {
self->_selectButton.imageView.contentMode = UIViewContentModeCenter;
} else {
self->_selectButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
}
});
}
- (void)showPhotoBytes { - (void)showPhotoBytes {
[[TZImageManager manager] getPhotosBytesWithArray:@[_models[_currentIndex]] completion:^(NSString *totalBytes) { [[TZImageManager manager] getPhotosBytesWithArray:@[_models[_currentIndex]] completion:^(NSString *totalBytes) {
self->_originalPhotoLabel.text = [NSString stringWithFormat:@"(%@)",totalBytes]; self->_originalPhotoLabel.text = [NSString stringWithFormat:@"(%@)",totalBytes];
......
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
@property (weak, nonatomic) IBOutlet UISwitch *allowCropSwitch; @property (weak, nonatomic) IBOutlet UISwitch *allowCropSwitch;
@property (weak, nonatomic) IBOutlet UISwitch *needCircleCropSwitch; @property (weak, nonatomic) IBOutlet UISwitch *needCircleCropSwitch;
@property (weak, nonatomic) IBOutlet UISwitch *allowPickingMuitlpleVideoSwitch; @property (weak, nonatomic) IBOutlet UISwitch *allowPickingMuitlpleVideoSwitch;
@property (weak, nonatomic) IBOutlet UISwitch *showSelectedIndexSwitch;
@end @end
@implementation ViewController @implementation ViewController
...@@ -106,7 +107,7 @@ ...@@ -106,7 +107,7 @@
- (void)viewDidLayoutSubviews { - (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews]; [super viewDidLayoutSubviews];
NSInteger contentSizeH = 13 * 35 + 20; NSInteger contentSizeH = 14 * 35 + 20;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.scrollView.contentSize = CGSizeMake(0, contentSizeH + 5); self.scrollView.contentSize = CGSizeMake(0, contentSizeH + 5);
}); });
...@@ -182,6 +183,7 @@ ...@@ -182,6 +183,7 @@
imagePickerVc.allowPickingGif = self.allowPickingGifSwitch.isOn; imagePickerVc.allowPickingGif = self.allowPickingGifSwitch.isOn;
imagePickerVc.allowPickingOriginalPhoto = self.allowPickingOriginalPhotoSwitch.isOn; imagePickerVc.allowPickingOriginalPhoto = self.allowPickingOriginalPhotoSwitch.isOn;
imagePickerVc.allowPickingMultipleVideo = self.allowPickingMuitlpleVideoSwitch.isOn; imagePickerVc.allowPickingMultipleVideo = self.allowPickingMuitlpleVideoSwitch.isOn;
imagePickerVc.showSelectedIndex = self.showSelectedIndexSwitch.isOn;
imagePickerVc.isSelectOriginalPhoto = _isSelectOriginalPhoto; imagePickerVc.isSelectOriginalPhoto = _isSelectOriginalPhoto;
[imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) { [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
self->_selectedPhotos = [NSMutableArray arrayWithArray:photos]; self->_selectedPhotos = [NSMutableArray arrayWithArray:photos];
...@@ -248,6 +250,7 @@ ...@@ -248,6 +250,7 @@
// imagePickerVc.oKButtonTitleColorDisabled = [UIColor lightGrayColor]; // imagePickerVc.oKButtonTitleColorDisabled = [UIColor lightGrayColor];
// imagePickerVc.oKButtonTitleColorNormal = [UIColor greenColor]; // imagePickerVc.oKButtonTitleColorNormal = [UIColor greenColor];
// imagePickerVc.navigationBar.translucent = NO; // imagePickerVc.navigationBar.translucent = NO;
imagePickerVc.iconThemeColor = [UIColor redColor];
// 3. Set allow picking video & photo & originalPhoto or not // 3. Set allow picking video & photo & originalPhoto or not
// 3. 设置是否可以选择视频/图片/原图 // 3. 设置是否可以选择视频/图片/原图
...@@ -298,6 +301,9 @@ ...@@ -298,6 +301,9 @@
// imagePickerVc.isStatusBarDefault = NO; // imagePickerVc.isStatusBarDefault = NO;
imagePickerVc.statusBarStyle = UIStatusBarStyleLightContent; imagePickerVc.statusBarStyle = UIStatusBarStyleLightContent;
// 设置是否显示图片序号
imagePickerVc.showSelectedIndex = self.showSelectedIndexSwitch.isOn;
// 设置首选语言 / Set preferred language // 设置首选语言 / Set preferred language
// imagePickerVc.preferredLanguage = @"zh-Hans"; // imagePickerVc.preferredLanguage = @"zh-Hans";
......
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