Commit 7726e364 authored by chendichuan's avatar chendichuan

UPDATE 支持裁剪图片时设置TZImagePickerController...

UPDATE 支持裁剪图片时设置TZImagePickerController scaleAspectFillCrop属性为YES时,图片自动按照UIViewContentModeScaleAspectFill模式等比缩放填充cropRect区域
parent cfae6b3f
...@@ -159,6 +159,7 @@ ...@@ -159,6 +159,7 @@
/// 单选模式,maxImagesCount为1时才生效 /// 单选模式,maxImagesCount为1时才生效
@property (nonatomic, assign) BOOL showSelectBtn; ///< 在单选模式下,照片列表页中,显示选择按钮,默认为NO @property (nonatomic, assign) BOOL showSelectBtn; ///< 在单选模式下,照片列表页中,显示选择按钮,默认为NO
@property (nonatomic, assign) BOOL allowCrop; ///< 允许裁剪,默认为YES,showSelectBtn为NO才生效 @property (nonatomic, assign) BOOL allowCrop; ///< 允许裁剪,默认为YES,showSelectBtn为NO才生效
@property (nonatomic, assign) BOOL scaleAspectFillCrop; ///< 是否图片等比缩放填充cropRect区域
@property (nonatomic, assign) CGRect cropRect; ///< 裁剪框的尺寸 @property (nonatomic, assign) CGRect cropRect; ///< 裁剪框的尺寸
@property (nonatomic, assign) CGRect cropRectPortrait; ///< 裁剪框的尺寸(竖屏) @property (nonatomic, assign) CGRect cropRectPortrait; ///< 裁剪框的尺寸(竖屏)
@property (nonatomic, assign) CGRect cropRectLandscape; ///< 裁剪框的尺寸(横屏) @property (nonatomic, assign) CGRect cropRectLandscape; ///< 裁剪框的尺寸(横屏)
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
@property (nonatomic, assign) BOOL allowCrop; @property (nonatomic, assign) BOOL allowCrop;
@property (nonatomic, assign) CGRect cropRect; @property (nonatomic, assign) CGRect cropRect;
@property (nonatomic, assign) BOOL scaleAspectFillCrop;
- (void)recoverSubviews; - (void)recoverSubviews;
...@@ -40,7 +41,7 @@ ...@@ -40,7 +41,7 @@
@property (nonatomic, assign) BOOL allowCrop; @property (nonatomic, assign) BOOL allowCrop;
@property (nonatomic, assign) CGRect cropRect; @property (nonatomic, assign) CGRect cropRect;
@property (nonatomic, assign) BOOL scaleAspectFillCrop;
@property (nonatomic, strong) TZAssetModel *model; @property (nonatomic, strong) TZAssetModel *model;
@property (nonatomic, strong) id asset; @property (nonatomic, strong) id asset;
@property (nonatomic, copy) void (^singleTapGestureBlock)(void); @property (nonatomic, copy) void (^singleTapGestureBlock)(void);
......
...@@ -78,6 +78,11 @@ ...@@ -78,6 +78,11 @@
_previewView.allowCrop = allowCrop; _previewView.allowCrop = allowCrop;
} }
- (void)setScaleAspectFillCrop:(BOOL)scaleAspectFillCrop {
_scaleAspectFillCrop = scaleAspectFillCrop;
_previewView.scaleAspectFillCrop = scaleAspectFillCrop;
}
- (void)setCropRect:(CGRect)cropRect { - (void)setCropRect:(CGRect)cropRect {
_cropRect = cropRect; _cropRect = cropRect;
_previewView.cropRect = cropRect; _previewView.cropRect = cropRect;
...@@ -201,7 +206,14 @@ ...@@ -201,7 +206,14 @@
self.imageRequestID = [[TZImageManager manager] getPhotoWithAsset:asset completion:^(UIImage *photo, NSDictionary *info, BOOL isDegraded) { self.imageRequestID = [[TZImageManager manager] getPhotoWithAsset:asset completion:^(UIImage *photo, NSDictionary *info, BOOL isDegraded) {
if (![asset isEqual:self->_asset]) return; if (![asset isEqual:self->_asset]) return;
self.imageView.image = photo; self.imageView.image = photo;
CGFloat scale = MAX(self.cropRect.size.width / self.imageView.tz_width, self.cropRect.size.height / self.imageView.tz_height);
[self resizeSubviews]; [self resizeSubviews];
if (self.scaleAspectFillCrop && scale > 1) { // 如果设置图片缩放裁剪并且图片需要缩放
self.scrollView.minimumZoomScale = scale;
self.scrollView.maximumZoomScale = scale * 2;
[self.scrollView setZoomScale:scale animated:YES];
}
self->_progressView.hidden = YES; self->_progressView.hidden = YES;
if (self.imageProgressUpdateBlock) { if (self.imageProgressUpdateBlock) {
self.imageProgressUpdateBlock(1); self.imageProgressUpdateBlock(1);
...@@ -229,7 +241,7 @@ ...@@ -229,7 +241,7 @@
} }
- (void)recoverSubviews { - (void)recoverSubviews {
[_scrollView setZoomScale:1.0 animated:NO]; [_scrollView setZoomScale:_scrollView.minimumZoomScale animated:NO];
[self resizeSubviews]; [self resizeSubviews];
} }
...@@ -305,9 +317,9 @@ ...@@ -305,9 +317,9 @@
#pragma mark - UITapGestureRecognizer Event #pragma mark - UITapGestureRecognizer Event
- (void)doubleTap:(UITapGestureRecognizer *)tap { - (void)doubleTap:(UITapGestureRecognizer *)tap {
if (_scrollView.zoomScale > 1.0) { if (_scrollView.zoomScale > _scrollView.minimumZoomScale) {
_scrollView.contentInset = UIEdgeInsetsZero; _scrollView.contentInset = UIEdgeInsetsZero;
[_scrollView setZoomScale:1.0 animated:YES]; [_scrollView setZoomScale:_scrollView.minimumZoomScale animated:YES];
} else { } else {
CGPoint touchPoint = [tap locationInView:self.imageView]; CGPoint touchPoint = [tap locationInView:self.imageView];
CGFloat newZoomScale = _scrollView.maximumZoomScale; CGFloat newZoomScale = _scrollView.maximumZoomScale;
......
...@@ -464,6 +464,7 @@ ...@@ -464,6 +464,7 @@
TZPhotoPreviewCell *photoPreviewCell = (TZPhotoPreviewCell *)cell; TZPhotoPreviewCell *photoPreviewCell = (TZPhotoPreviewCell *)cell;
photoPreviewCell.cropRect = _tzImagePickerVc.cropRect; photoPreviewCell.cropRect = _tzImagePickerVc.cropRect;
photoPreviewCell.allowCrop = _tzImagePickerVc.allowCrop; photoPreviewCell.allowCrop = _tzImagePickerVc.allowCrop;
photoPreviewCell.scaleAspectFillCrop = _tzImagePickerVc.scaleAspectFillCrop;
__weak typeof(_tzImagePickerVc) weakTzImagePickerVc = _tzImagePickerVc; __weak typeof(_tzImagePickerVc) weakTzImagePickerVc = _tzImagePickerVc;
__weak typeof(_collectionView) weakCollectionView = _collectionView; __weak typeof(_collectionView) weakCollectionView = _collectionView;
__weak typeof(photoPreviewCell) weakCell = photoPreviewCell; __weak typeof(photoPreviewCell) weakCell = photoPreviewCell;
......
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