Commit c046af73 authored by banchichen's avatar banchichen

准备加入裁剪功能,初步搭建代码

parent f6f3f2fe
Pod::Spec.new do |s|
s.name = "TZImagePickerController"
s.version = "1.7.0"
s.version = "1.7.1"
s.summary = "A clone of UIImagePickerController, support picking multiple photos、original photo and video"
s.homepage = "https://github.com/banchichen/TZImagePickerController"
s.license = "MIT"
s.author = { "banchichen" => "tanzhenios@foxmail.com" }
s.platform = :ios
s.ios.deployment_target = "6.0"
s.source = { :git => "https://github.com/banchichen/TZImagePickerController.git", :tag => "1.7.0" }
s.source = { :git => "https://github.com/banchichen/TZImagePickerController.git", :tag => "1.7.1" }
s.requires_arc = true
s.resources = "TZImagePickerController/TZImagePickerController/*.{png,xib,nib,bundle}"
s.source_files = "TZImagePickerController/TZImagePickerController/*.{h,m}"
......
......@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.7.1</string>
<string>1.7.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
......
......@@ -29,7 +29,7 @@ typedef enum : NSUInteger {
@property (nonatomic, copy) NSString *photoSelImageName;
@property (nonatomic, copy) NSString *photoDefImageName;
@property (nonatomic, assign) NSInteger maxImagesCount;
@property (nonatomic, assign) BOOL showSelectBtn;
@end
......
......@@ -77,13 +77,13 @@
}
}
- (void)setMaxImagesCount:(NSInteger)maxImagesCount {
_maxImagesCount = maxImagesCount;
- (void)setShowSelectBtn:(BOOL)showSelectBtn {
_showSelectBtn = showSelectBtn;
if (!self.selectPhotoButton.hidden) {
self.selectPhotoButton.hidden = maxImagesCount == 1;
self.selectPhotoButton.hidden = !showSelectBtn;
}
if (!self.selectImageView.hidden) {
self.selectImageView.hidden = maxImagesCount == 1;
self.selectImageView.hidden = !showSelectBtn;
}
}
......
......@@ -4,7 +4,7 @@
//
// Created by 谭真 on 15/12/24.
// Copyright © 2015年 谭真. All rights reserved.
// version 1.7.1 - 2016.10.18
// version 1.7.2 - 2016.12.2
/*
经过测试,比起xib的方式,把TZAssetCell改用纯代码的方式来写,滑动帧数明显提高了(约提高10帧左右)
......@@ -92,6 +92,12 @@
/// 隐藏不可以选中的图片,默认是NO,不推荐将其设置为YES
@property (nonatomic, assign) BOOL hideWhenCanNotSelect;
/// Single selection mode, valid when maxImagesCount = 1
/// 单选模式,maxImagesCount为1时才生效
@property (nonatomic, assign) BOOL showSelectBtn; ///< 在单选模式下,照片列表页中,显示选择按钮,默认为NO
@property (nonatomic, assign) BOOL allowCrop; ///< 允许裁剪,默认为YES,showSelectBtn为NO才生效
@property (nonatomic, assign) CGRect cropRect; ///< 裁剪框的尺寸
- (void)showAlertWithTitle:(NSString *)title;
- (void)showProgressHUD;
- (void)hideProgressHUD;
......
......@@ -4,7 +4,7 @@
//
// Created by 谭真 on 15/12/24.
// Copyright © 2015年 谭真. All rights reserved.
// version 1.7.1 - 2016.10.18
// version 1.7.2 - 2016.12.2
#import "TZImagePickerController.h"
#import "TZPhotoPickerController.h"
......@@ -174,7 +174,7 @@
previewVc.photos = [NSMutableArray arrayWithArray:selectedPhotos];
previewVc.currentIndex = index;
__weak typeof(self) weakSelf = self;
[previewVc setOkButtonClickBlockWithPreviewType:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
[previewVc setDoneButtonClickBlockWithPreviewType:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
if (weakSelf.didFinishPickingPhotosHandle) {
weakSelf.didFinishPickingPhotosHandle(photos,assets,isSelectOriginalPhoto);
}
......@@ -274,6 +274,36 @@
}
}
- (void)setMaxImagesCount:(NSInteger)maxImagesCount {
_maxImagesCount = maxImagesCount;
if (maxImagesCount > 1) {
_showSelectBtn = YES;
}
}
- (void)setShowSelectBtn:(BOOL)showSelectBtn {
_showSelectBtn = showSelectBtn;
// 多选模式下,不允许让showSelectBtn为NO
if (!showSelectBtn && _maxImagesCount > 1) {
_showSelectBtn = YES;
}
}
- (void)setAllowCrop:(BOOL)allowCrop {
_allowCrop = allowCrop;
if (allowCrop) { // 允许裁剪的时候,不能选原图
self.allowPickingOriginalPhoto = NO;
}
}
- (CGRect)cropRect {
if (_cropRect.size.width > 0) {
return _cropRect;
}
CGFloat cropViewWH = self.view.tz_width - 2;
return CGRectMake(1, (self.view.tz_height - self.view.tz_width) / 2, cropViewWH, cropViewWH);
}
- (void)setTimeout:(NSInteger)timeout {
_timeout = timeout;
if (timeout < 5) {
......@@ -440,6 +470,7 @@
if (imagePickerVc.autoDismiss) {
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
// 兼容旧版本
if ([imagePickerVc.pickerDelegate respondsToSelector:@selector(imagePickerControllerDidCancel:)]) {
[imagePickerVc.pickerDelegate imagePickerControllerDidCancel:imagePickerVc];
}
......
......@@ -121,7 +121,7 @@ static CGSize AssetGridThumbnailSize;
layout.minimumLineSpacing = margin;
CGFloat top = 44;
if (iOS7Later) top += 20;
CGFloat collectionViewHeight = tzImagePickerVc.maxImagesCount > 1 ? self.view.tz_height - 50 - top : self.view.tz_height - top;
CGFloat collectionViewHeight = tzImagePickerVc.showSelectBtn ? self.view.tz_height - 50 - top : self.view.tz_height - top;
_collectionView = [[TZCollectionView alloc] initWithFrame:CGRectMake(0, top, self.view.tz_width, collectionViewHeight) collectionViewLayout:layout];
_collectionView.backgroundColor = [UIColor whiteColor];
_collectionView.dataSource = self;
......@@ -160,7 +160,7 @@ static CGSize AssetGridThumbnailSize;
- (void)configBottomToolBar {
TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
if (tzImagePickerVc.maxImagesCount <= 1) return;
if (!tzImagePickerVc.showSelectBtn) return;
UIView *bottomToolBar = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.tz_height - 50, self.view.tz_width, 50)];
CGFloat rgb = 253 / 255.0;
......@@ -170,7 +170,7 @@ static CGSize AssetGridThumbnailSize;
CGFloat previewWidth = [previewText boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) options:NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16]} context:nil].size.width;
_previewButton = [UIButton buttonWithType:UIButtonTypeCustom];
_previewButton.frame = CGRectMake(10, 3, previewWidth + 2, 44);
_previewButton.tz_width = tzImagePickerVc.maxImagesCount <= 1 ? 0 : previewWidth + 2;
_previewButton.tz_width = !tzImagePickerVc.showSelectBtn ? 0 : previewWidth + 2;
[_previewButton addTarget:self action:@selector(previewButtonClick) forControlEvents:UIControlEventTouchUpInside];
_previewButton.titleLabel.font = [UIFont systemFontOfSize:16];
[_previewButton setTitle:previewText forState:UIControlStateNormal];
......@@ -362,7 +362,7 @@ static CGSize AssetGridThumbnailSize;
model = _models[indexPath.row - 1];
}
cell.model = model;
cell.maxImagesCount = tzImagePickerVc.maxImagesCount;
cell.showSelectBtn = tzImagePickerVc.showSelectBtn;
__weak typeof(cell) weakCell = cell;
__weak typeof(self) weakSelf = self;
......@@ -482,15 +482,18 @@ static CGSize AssetGridThumbnailSize;
- (void)pushPhotoPrevireViewController:(TZPhotoPreviewController *)photoPreviewVc {
__weak typeof(self) weakSelf = self;
photoPreviewVc.isSelectOriginalPhoto = _isSelectOriginalPhoto;
photoPreviewVc.backButtonClickBlock = ^(BOOL isSelectOriginalPhoto) {
[photoPreviewVc setBackButtonClickBlock:^(BOOL isSelectOriginalPhoto) {
weakSelf.isSelectOriginalPhoto = isSelectOriginalPhoto;
[weakSelf.collectionView reloadData];
[weakSelf refreshBottomToolBarStatus];
};
photoPreviewVc.okButtonClickBlock = ^(BOOL isSelectOriginalPhoto){
}];
[photoPreviewVc setDoneButtonClickBlock:^(BOOL isSelectOriginalPhoto) {
weakSelf.isSelectOriginalPhoto = isSelectOriginalPhoto;
[weakSelf okButtonClick];
};
}];
[photoPreviewVc setDoneButtonClickBlockCropMode:^(UIImage *cropedImage, id asset) {
[weakSelf didGetAllPhotos:@[cropedImage] assets:@[asset] infoArr:nil];
}];
[self.navigationController pushViewController:photoPreviewVc animated:YES];
}
......
......@@ -14,6 +14,13 @@
@property (nonatomic, strong) TZAssetModel *model;
@property (nonatomic, copy) void (^singleTapGestureBlock)();
@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) UIView *imageContainerView;
@property (nonatomic, assign) BOOL allowCrop;
@property (nonatomic, assign) CGRect cropRect;
- (void)recoverSubviews;
@end
......@@ -14,9 +14,6 @@
@interface TZPhotoPreviewCell ()<UIGestureRecognizerDelegate,UIScrollViewDelegate> {
CGFloat _aspectRatio;
}
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UIView *imageContainerView;
@end
@implementation TZPhotoPreviewCell
......@@ -43,10 +40,12 @@
_imageContainerView = [[UIView alloc] init];
_imageContainerView.clipsToBounds = YES;
_imageContainerView.contentMode = UIViewContentModeScaleAspectFill;
[_scrollView addSubview:_imageContainerView];
_imageView = [[UIImageView alloc] init];
_imageView.backgroundColor = [UIColor colorWithWhite:1.000 alpha:0.500];
_imageView.contentMode = UIViewContentModeScaleAspectFill;
_imageView.clipsToBounds = YES;
[_imageContainerView addSubview:_imageView];
......@@ -91,7 +90,12 @@
if (_imageContainerView.tz_height > self.tz_height && _imageContainerView.tz_height - self.tz_height <= 1) {
_imageContainerView.tz_height = self.tz_height;
}
_scrollView.contentSize = CGSizeMake(self.scrollView.tz_width, MAX(_imageContainerView.tz_height, self.tz_height));
CGFloat contentSizeH = MAX(_imageContainerView.tz_height, self.tz_height);
if (_allowCrop) {
_scrollView.contentSize = CGSizeMake(self.scrollView.tz_width, contentSizeH);
} else {
_scrollView.contentSize = CGSizeMake(self.scrollView.tz_width, contentSizeH);
}
[_scrollView scrollRectToVisible:self.bounds animated:NO];
_scrollView.alwaysBounceVertical = _imageContainerView.tz_height <= self.tz_height ? NO : YES;
_imageView.frame = _imageContainerView.bounds;
......@@ -129,4 +133,8 @@
self.imageContainerView.center = CGPointMake(scrollView.contentSize.width * 0.5 + offsetX, scrollView.contentSize.height * 0.5 + offsetY);
}
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale {
}
@end
......@@ -17,7 +17,8 @@
/// Return the new selected photos / 返回最新的选中图片数组
@property (nonatomic, copy) void (^backButtonClickBlock)(BOOL isSelectOriginalPhoto);
@property (nonatomic, copy) void (^okButtonClickBlock)(BOOL isSelectOriginalPhoto);
@property (nonatomic, copy) void (^okButtonClickBlockWithPreviewType)(NSArray<UIImage *> *photos,NSArray *assets,BOOL isSelectOriginalPhoto);
@property (nonatomic, copy) void (^doneButtonClickBlock)(BOOL isSelectOriginalPhoto);
@property (nonatomic, copy) void (^doneButtonClickBlockCropMode)(UIImage *cropedImage,id asset);
@property (nonatomic, copy) void (^doneButtonClickBlockWithPreviewType)(NSArray<UIImage *> *photos,NSArray *assets,BOOL isSelectOriginalPhoto);
@end
......@@ -20,7 +20,7 @@
self.backgroundColor = [UIColor whiteColor];
_imageView = [[UIImageView alloc] init];
_imageView.backgroundColor = [UIColor colorWithWhite:1.000 alpha:0.500];
_imageView.contentMode = UIViewContentModeScaleAspectFill;
_imageView.contentMode = UIViewContentModeScaleAspectFit;
[self addSubview:_imageView];
self.clipsToBounds = YES;
......
......@@ -69,6 +69,7 @@
_selectedPhotos = [NSMutableArray array];
_selectedAssets = [NSMutableArray array];
[self configCollectionView];
self.maxCountTF.text = @"1";
}
- (BOOL)prefersStatusBarHidden {
......@@ -225,6 +226,13 @@
// imagePickerVc.minPhotoWidthSelectable = 3000;
// imagePickerVc.minPhotoHeightSelectable = 2000;
/// 5. Single selection mode, valid when maxImagesCount = 1
/// 5. 单选模式,maxImagesCount为1时才生效
imagePickerVc.showSelectBtn = NO;
imagePickerVc.allowCrop = YES;
NSInteger cropWH = self.view.tz_width - 40;
imagePickerVc.cropRect = CGRectMake(20, (self.view.tz_height - cropWH) / 2 + 50, cropWH, cropWH - 100);
#pragma mark - 到这里为止
// You can get the photos by block, the same as by delegate.
......
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