Commit 2eb5b0a8 authored by tanzhen's avatar tanzhen

新增可设置columnNumber的初始化方法,可自定义photoPicker页每行展示照片个数,默认为每行4个

parent 5894fb96
...@@ -18,10 +18,10 @@ ...@@ -18,10 +18,10 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="4Ae-5T-gEc" userLabel="TopContentView"> <view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="4Ae-5T-gEc" userLabel="TopContentView">
<rect key="frame" x="0.0" y="0.0" width="320" height="344"/> <rect key="frame" x="0.0" y="0.0" width="320" height="340"/>
<subviews> <subviews>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="obE-hs-XLa" userLabel="View1"> <view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="obE-hs-XLa" userLabel="View1">
<rect key="frame" x="0.0" y="20" width="320" height="44"/> <rect key="frame" x="0.0" y="20" width="320" height="40"/>
<subviews> <subviews>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="jpa-B9-8n6"> <switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="jpa-B9-8n6">
<rect key="frame" x="225" y="6" width="51" height="31"/> <rect key="frame" x="225" y="6" width="51" height="31"/>
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view> </view>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="wWK-ob-W4A" userLabel="View2"> <view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="wWK-ob-W4A" userLabel="View2">
<rect key="frame" x="0.0" y="64" width="320" height="44"/> <rect key="frame" x="0.0" y="60" width="320" height="40"/>
<subviews> <subviews>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Rbt-bh-r0x"> <switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Rbt-bh-r0x">
<rect key="frame" x="225" y="6" width="51" height="31"/> <rect key="frame" x="225" y="6" width="51" height="31"/>
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view> </view>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="kJv-DR-NlY" userLabel="View3"> <view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="kJv-DR-NlY" userLabel="View3">
<rect key="frame" x="0.0" y="108" width="320" height="44"/> <rect key="frame" x="0.0" y="100" width="320" height="40"/>
<subviews> <subviews>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="a58-aK-ZB0"> <switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="a58-aK-ZB0">
<rect key="frame" x="225" y="6" width="51" height="31"/> <rect key="frame" x="225" y="6" width="51" height="31"/>
...@@ -72,7 +72,7 @@ ...@@ -72,7 +72,7 @@
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view> </view>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Z20-6k-hhA" userLabel="View4"> <view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Z20-6k-hhA" userLabel="View4">
<rect key="frame" x="0.0" y="152" width="320" height="44"/> <rect key="frame" x="0.0" y="140" width="320" height="44"/>
<subviews> <subviews>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="iRQ-aE-1KG"> <switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="iRQ-aE-1KG">
<rect key="frame" x="225" y="6" width="51" height="31"/> <rect key="frame" x="225" y="6" width="51" height="31"/>
...@@ -90,7 +90,7 @@ ...@@ -90,7 +90,7 @@
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view> </view>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="jKt-h1-BC7" userLabel="View5"> <view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="jKt-h1-BC7" userLabel="View5">
<rect key="frame" x="0.0" y="196" width="320" height="44"/> <rect key="frame" x="0.0" y="180" width="320" height="40"/>
<subviews> <subviews>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="4L3-Da-pcd"> <switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="4L3-Da-pcd">
<rect key="frame" x="225" y="6" width="51" height="31"/> <rect key="frame" x="225" y="6" width="51" height="31"/>
...@@ -108,7 +108,7 @@ ...@@ -108,7 +108,7 @@
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view> </view>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Qrr-87-KzM" userLabel="View6"> <view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Qrr-87-KzM" userLabel="View6">
<rect key="frame" x="0.0" y="240" width="320" height="44"/> <rect key="frame" x="0.0" y="220" width="320" height="40"/>
<subviews> <subviews>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="uHt-bT-lBZ"> <switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="uHt-bT-lBZ">
<rect key="frame" x="225" y="6" width="51" height="31"/> <rect key="frame" x="225" y="6" width="51" height="31"/>
...@@ -126,7 +126,7 @@ ...@@ -126,7 +126,7 @@
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view> </view>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="PA2-zk-4Ey" userLabel="View7"> <view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="PA2-zk-4Ey" userLabel="View7">
<rect key="frame" x="0.0" y="284" width="320" height="44"/> <rect key="frame" x="0.0" y="260" width="320" height="40"/>
<subviews> <subviews>
<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="rK3-1U-kcW"> <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="rK3-1U-kcW">
<rect key="frame" x="0.0" y="0.0" width="200" height="44"/> <rect key="frame" x="0.0" y="0.0" width="200" height="44"/>
...@@ -142,6 +142,23 @@ ...@@ -142,6 +142,23 @@
</subviews> </subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view> </view>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="VUP-wm-Ah2" userLabel="View8">
<rect key="frame" x="0.0" y="300" width="320" height="40"/>
<subviews>
<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="fbH-6q-oeE">
<rect key="frame" x="0.0" y="0.0" width="200" height="44"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" text="4" borderStyle="roundedRect" textAlignment="center" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="YR1-nJ-q0v">
<rect key="frame" x="220" y="7" width="80" height="30"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" keyboardType="numberPad"/>
</textField>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
</subviews> </subviews>
</view> </view>
</subviews> </subviews>
...@@ -152,6 +169,7 @@ ...@@ -152,6 +169,7 @@
<outlet property="allowPickingImageSwitch" destination="iRQ-aE-1KG" id="V7a-u6-cLv"/> <outlet property="allowPickingImageSwitch" destination="iRQ-aE-1KG" id="V7a-u6-cLv"/>
<outlet property="allowPickingOriginalPhotoSwitch" destination="4L3-Da-pcd" id="KFm-Zl-dpD"/> <outlet property="allowPickingOriginalPhotoSwitch" destination="4L3-Da-pcd" id="KFm-Zl-dpD"/>
<outlet property="allowPickingVideoSwitch" destination="a58-aK-ZB0" id="9Ti-hW-QRj"/> <outlet property="allowPickingVideoSwitch" destination="a58-aK-ZB0" id="9Ti-hW-QRj"/>
<outlet property="columnNumberTF" destination="YR1-nJ-q0v" id="TE2-iH-EWE"/>
<outlet property="maxCountTF" destination="37K-cO-hgf" id="776-gE-tea"/> <outlet property="maxCountTF" destination="37K-cO-hgf" id="776-gE-tea"/>
<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"/>
......
...@@ -23,6 +23,10 @@ ...@@ -23,6 +23,10 @@
/// Default is 600px / 默认600像素宽 /// Default is 600px / 默认600像素宽
@property (nonatomic, assign) CGFloat photoPreviewMaxWidth; @property (nonatomic, assign) CGFloat photoPreviewMaxWidth;
/// Default is 4, Use in photos collectionView in TZPhotoPickerController
/// 默认4列, TZPhotoPickerController中的照片collectionView
@property (nonatomic, assign) NSInteger columnNumber;
/// Sort photos ascending by modificationDate,Default is YES /// Sort photos ascending by modificationDate,Default is YES
/// 对照片排序,按修改时间升序,默认是YES。如果设置为NO,最新的照片会显示在最前面,内部的拍照按钮会排在第一个 /// 对照片排序,按修改时间升序,默认是YES。如果设置为NO,最新的照片会显示在最前面,内部的拍照按钮会排在第一个
@property (nonatomic, assign) BOOL sortAscendingByModificationDate; @property (nonatomic, assign) BOOL sortAscendingByModificationDate;
......
...@@ -29,22 +29,28 @@ static CGFloat TZScreenScale; ...@@ -29,22 +29,28 @@ static CGFloat TZScreenScale;
static dispatch_once_t onceToken; static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{ dispatch_once(&onceToken, ^{
manager = [[self alloc] init]; manager = [[self alloc] init];
manager.cachingImageManager = [[PHCachingImageManager alloc] init]; if (iOS8Later) {
// manager.cachingImageManager.allowsCachingHighQualityImages = YES; manager.cachingImageManager = [[PHCachingImageManager alloc] init];
// manager.cachingImageManager.allowsCachingHighQualityImages = YES;
}
TZScreenWidth = [UIScreen mainScreen].bounds.size.width; TZScreenWidth = [UIScreen mainScreen].bounds.size.width;
// 测试发现,如果scale在plus真机上取到3.0,内存会增大特别多。故这里写死成2.0 // 测试发现,如果scale在plus真机上取到3.0,内存会增大特别多。故这里写死成2.0
TZScreenScale = 2.0; TZScreenScale = 2.0;
if (TZScreenWidth > 700) { if (TZScreenWidth > 700) {
TZScreenScale = 1.5; TZScreenScale = 1.5;
} }
CGFloat margin = 4;
CGFloat itemWH = (TZScreenWidth - 2 * margin - 4) / 4 - margin;
AssetGridThumbnailSize = CGSizeMake(itemWH * TZScreenScale, itemWH * TZScreenScale);
}); });
return manager; return manager;
} }
- (void)setColumnNumber:(NSInteger)columnNumber {
_columnNumber = columnNumber;
CGFloat margin = 4;
CGFloat itemWH = (TZScreenWidth - 2 * margin - 4) / columnNumber - margin;
AssetGridThumbnailSize = CGSizeMake(itemWH * TZScreenScale, itemWH * TZScreenScale);
}
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations" #pragma clang diagnostic ignored "-Wdeprecated-declarations"
- (ALAssetsLibrary *)assetLibrary { - (ALAssetsLibrary *)assetLibrary {
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
/// Use this init method / 用这个初始化方法 /// Use this init method / 用这个初始化方法
- (instancetype)initWithMaxImagesCount:(NSInteger)maxImagesCount delegate:(id<TZImagePickerControllerDelegate>)delegate; - (instancetype)initWithMaxImagesCount:(NSInteger)maxImagesCount delegate:(id<TZImagePickerControllerDelegate>)delegate;
- (instancetype)initWithMaxImagesCount:(NSInteger)maxImagesCount columnNumber:(NSInteger)columnNumber delegate:(id<TZImagePickerControllerDelegate>)delegate;
/// This init method just for previewing photos / 用这个初始化方法以预览图片 /// This init method just for previewing photos / 用这个初始化方法以预览图片
- (instancetype)initWithSelectedAssets:(NSMutableArray *)selectedAssets selectedPhotos:(NSMutableArray *)selectedPhotos index:(NSInteger)index; - (instancetype)initWithSelectedAssets:(NSMutableArray *)selectedAssets selectedPhotos:(NSMutableArray *)selectedPhotos index:(NSInteger)index;
...@@ -141,7 +142,7 @@ ...@@ -141,7 +142,7 @@
@interface TZAlbumPickerController : UIViewController @interface TZAlbumPickerController : UIViewController
@property (nonatomic, assign) NSInteger columnNumber;
@end @end
......
...@@ -27,6 +27,9 @@ ...@@ -27,6 +27,9 @@
UIStatusBarStyle _originStatusBarStyle; UIStatusBarStyle _originStatusBarStyle;
} }
/// Default is 4, Use in photos collectionView in TZPhotoPickerController
/// 默认4列, TZPhotoPickerController中的照片collectionView
@property (nonatomic, assign) NSInteger columnNumber;
@end @end
@implementation TZImagePickerController @implementation TZImagePickerController
...@@ -80,7 +83,12 @@ ...@@ -80,7 +83,12 @@
} }
- (instancetype)initWithMaxImagesCount:(NSInteger)maxImagesCount delegate:(id<TZImagePickerControllerDelegate>)delegate { - (instancetype)initWithMaxImagesCount:(NSInteger)maxImagesCount delegate:(id<TZImagePickerControllerDelegate>)delegate {
return [self initWithMaxImagesCount:maxImagesCount columnNumber:4 delegate:delegate];
}
- (instancetype)initWithMaxImagesCount:(NSInteger)maxImagesCount columnNumber:(NSInteger)columnNumber delegate:(id<TZImagePickerControllerDelegate>)delegate {
TZAlbumPickerController *albumPickerVc = [[TZAlbumPickerController alloc] init]; TZAlbumPickerController *albumPickerVc = [[TZAlbumPickerController alloc] init];
albumPickerVc.columnNumber = columnNumber;
self = [super initWithRootViewController:albumPickerVc]; self = [super initWithRootViewController:albumPickerVc];
if (self) { if (self) {
self.maxImagesCount = maxImagesCount > 0 ? maxImagesCount : 9; // Default is 9 / 默认最大可选9张图片 self.maxImagesCount = maxImagesCount > 0 ? maxImagesCount : 9; // Default is 9 / 默认最大可选9张图片
...@@ -100,6 +108,7 @@ ...@@ -100,6 +108,7 @@
self.autoDismiss = YES; self.autoDismiss = YES;
self.barItemTextFont = [UIFont systemFontOfSize:15]; self.barItemTextFont = [UIFont systemFontOfSize:15];
self.barItemTextColor = [UIColor whiteColor]; self.barItemTextColor = [UIColor whiteColor];
self.columnNumber = columnNumber;
[self configDefaultImageName]; [self configDefaultImageName];
if (![[TZImageManager manager] authorizationStatusAuthorized]) { if (![[TZImageManager manager] authorizationStatusAuthorized]) {
...@@ -183,6 +192,7 @@ ...@@ -183,6 +192,7 @@
if (_pushToPhotoPickerVc) { if (_pushToPhotoPickerVc) {
TZPhotoPickerController *photoPickerVc = [[TZPhotoPickerController alloc] init]; TZPhotoPickerController *photoPickerVc = [[TZPhotoPickerController alloc] init];
photoPickerVc.isFirstAppear = YES; photoPickerVc.isFirstAppear = YES;
photoPickerVc.columnNumber = self.columnNumber;
[[TZImageManager manager] getCameraRollAlbum:self.allowPickingVideo allowPickingImage:self.allowPickingImage completion:^(TZAlbumModel *model) { [[TZImageManager manager] getCameraRollAlbum:self.allowPickingVideo allowPickingImage:self.allowPickingImage completion:^(TZAlbumModel *model) {
photoPickerVc.model = model; photoPickerVc.model = model;
[self pushViewController:photoPickerVc animated:YES]; [self pushViewController:photoPickerVc animated:YES];
...@@ -255,6 +265,19 @@ ...@@ -255,6 +265,19 @@
} }
} }
- (void)setColumnNumber:(NSInteger)columnNumber {
_columnNumber = columnNumber;
if (columnNumber <= 2) {
_columnNumber = 2;
} else if (columnNumber >= 6) {
_columnNumber = 6;
}
TZAlbumPickerController *albumPickerVc = [self.childViewControllers firstObject];
albumPickerVc.columnNumber = _columnNumber;
[TZImageManager manager].columnNumber = _columnNumber;
}
- (void)setPhotoPreviewMaxWidth:(CGFloat)photoPreviewMaxWidth { - (void)setPhotoPreviewMaxWidth:(CGFloat)photoPreviewMaxWidth {
_photoPreviewMaxWidth = photoPreviewMaxWidth; _photoPreviewMaxWidth = photoPreviewMaxWidth;
if (photoPreviewMaxWidth > 800) { if (photoPreviewMaxWidth > 800) {
...@@ -418,6 +441,7 @@ ...@@ -418,6 +441,7 @@
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
TZPhotoPickerController *photoPickerVc = [[TZPhotoPickerController alloc] init]; TZPhotoPickerController *photoPickerVc = [[TZPhotoPickerController alloc] init];
photoPickerVc.columnNumber = self.columnNumber;
TZAlbumModel *model = _albumArr[indexPath.row]; TZAlbumModel *model = _albumArr[indexPath.row];
photoPickerVc.model = model; photoPickerVc.model = model;
__weak typeof(self) weakSelf = self; __weak typeof(self) weakSelf = self;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
@interface TZPhotoPickerController : UIViewController @interface TZPhotoPickerController : UIViewController
@property (nonatomic, assign) BOOL isFirstAppear; @property (nonatomic, assign) BOOL isFirstAppear;
@property (nonatomic, assign) NSInteger columnNumber;
@property (nonatomic, strong) TZAlbumModel *model; @property (nonatomic, strong) TZAlbumModel *model;
@property (nonatomic, copy) void (^backButtonClickHandle)(TZAlbumModel *model); @property (nonatomic, copy) void (^backButtonClickHandle)(TZAlbumModel *model);
......
...@@ -110,26 +110,25 @@ static CGSize AssetGridThumbnailSize; ...@@ -110,26 +110,25 @@ static CGSize AssetGridThumbnailSize;
TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController; TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
CGFloat margin = 4; CGFloat margin = 5;
CGFloat itemWH = (self.view.tz_width - 2 * margin - 4) / 4 - margin; CGFloat itemWH = (self.view.tz_width - (self.columnNumber + 1) * margin) / self.columnNumber;
layout.itemSize = CGSizeMake(itemWH, itemWH); layout.itemSize = CGSizeMake(itemWH, itemWH);
layout.minimumInteritemSpacing = margin; layout.minimumInteritemSpacing = margin;
layout.minimumLineSpacing = margin; layout.minimumLineSpacing = margin;
CGFloat top = margin + 44; CGFloat top = 44;
if (iOS7Later) top += 20; if (iOS7Later) top += 20;
CGFloat collectionViewHeight = tzImagePickerVc.maxImagesCount > 1 ? self.view.tz_height - 50 - top : self.view.tz_height - top; CGFloat collectionViewHeight = tzImagePickerVc.maxImagesCount > 1 ? self.view.tz_height - 50 - top : self.view.tz_height - top;
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(margin, top, self.view.tz_width - 2 * margin, collectionViewHeight) collectionViewLayout:layout]; _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, top, self.view.tz_width, collectionViewHeight) collectionViewLayout:layout];
_collectionView.backgroundColor = [UIColor whiteColor]; _collectionView.backgroundColor = [UIColor whiteColor];
_collectionView.dataSource = self; _collectionView.dataSource = self;
_collectionView.delegate = self; _collectionView.delegate = self;
_collectionView.alwaysBounceHorizontal = NO; _collectionView.alwaysBounceHorizontal = NO;
if (iOS7Later) _collectionView.contentInset = UIEdgeInsetsMake(0, 0, 0, 2); _collectionView.contentInset = UIEdgeInsetsMake(margin, margin, margin, margin);
_collectionView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 0, -2);
if (_showTakePhotoBtn && tzImagePickerVc.allowTakePicture ) { if (_showTakePhotoBtn && tzImagePickerVc.allowTakePicture ) {
_collectionView.contentSize = CGSizeMake(self.view.tz_width, ((_model.count + 4) / 4) * self.view.tz_width); _collectionView.contentSize = CGSizeMake(self.view.tz_width, ((_model.count + self.columnNumber) / self.columnNumber) * self.view.tz_width);
} else { } else {
_collectionView.contentSize = CGSizeMake(self.view.tz_width, ((_model.count + 3) / 4) * self.view.tz_width); _collectionView.contentSize = CGSizeMake(self.view.tz_width, ((_model.count + self.columnNumber - 1) / self.columnNumber) * self.view.tz_width);
} }
[self.view addSubview:_collectionView]; [self.view addSubview:_collectionView];
[_collectionView registerClass:[TZAssetCell class] forCellWithReuseIdentifier:@"TZAssetCell"]; [_collectionView registerClass:[TZAssetCell class] forCellWithReuseIdentifier:@"TZAssetCell"];
......
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
[self configCollectionView]; [self configCollectionView];
[self configCustomNaviBar]; [self configCustomNaviBar];
[self configBottomToolBar]; [self configBottomToolBar];
self.view.clipsToBounds = YES;
} }
- (void)setPhotos:(NSMutableArray *)photos { - (void)setPhotos:(NSMutableArray *)photos {
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
@property (weak, nonatomic) IBOutlet UISwitch *allowPickingOriginalPhotoSwitch; ///< 允许选择原图 @property (weak, nonatomic) IBOutlet UISwitch *allowPickingOriginalPhotoSwitch; ///< 允许选择原图
@property (weak, nonatomic) IBOutlet UISwitch *showSheetSwitch; ///< 显示一个sheet,把拍照按钮放在外面 @property (weak, nonatomic) IBOutlet UISwitch *showSheetSwitch; ///< 显示一个sheet,把拍照按钮放在外面
@property (weak, nonatomic) IBOutlet UITextField *maxCountTF; ///< 照片最大可选张数,设置为1即为单选模式 @property (weak, nonatomic) IBOutlet UITextField *maxCountTF; ///< 照片最大可选张数,设置为1即为单选模式
@property (weak, nonatomic) IBOutlet UITextField *columnNumberTF;
@end @end
@implementation ViewController @implementation ViewController
...@@ -175,14 +176,14 @@ ...@@ -175,14 +176,14 @@
if (self.maxCountTF.text.integerValue <= 0) { if (self.maxCountTF.text.integerValue <= 0) {
return; return;
} }
TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:self.maxCountTF.text.integerValue delegate:self]; TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:self.maxCountTF.text.integerValue columnNumber:self.columnNumberTF.text.integerValue delegate:self];
#pragma mark - 四类个性化设置,这些参数都可以不传,此时会走默认设置 #pragma mark - 四类个性化设置,这些参数都可以不传,此时会走默认设置
imagePickerVc.isSelectOriginalPhoto = _isSelectOriginalPhoto; imagePickerVc.isSelectOriginalPhoto = _isSelectOriginalPhoto;
if (self.maxCountTF.text.integerValue > 1) { if (self.maxCountTF.text.integerValue > 1) {
// 1.如果你需要将拍照按钮放在外面,不要传这个参数 // 1.设置目前已经选中的图片数组
imagePickerVc.selectedAssets = _selectedAssets; // optional, 可选的 imagePickerVc.selectedAssets = _selectedAssets; // 目前已经选中的图片数组
} }
imagePickerVc.allowTakePicture = self.showTakePhotoBtnSwitch.isOn; // 在内部显示拍照按钮 imagePickerVc.allowTakePicture = self.showTakePhotoBtnSwitch.isOn; // 在内部显示拍照按钮
......
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