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
......@@ -29,6 +29,8 @@
UILabel *_numberLable;
UIButton *_originalPhotoButton;
UILabel *_originalPhotoLable;
UIView *_cropView;
}
@end
......@@ -45,6 +47,7 @@
}
[self configCollectionView];
[self configCustomNaviBar];
[self configCropView];
[self configBottomToolBar];
self.view.clipsToBounds = YES;
}
......@@ -88,7 +91,7 @@
[_selectButton setImage:[UIImage imageNamedFromMyBundle:tzImagePickerVc.photoDefImageName] forState:UIControlStateNormal];
[_selectButton setImage:[UIImage imageNamedFromMyBundle:tzImagePickerVc.photoSelImageName] forState:UIControlStateSelected];
[_selectButton addTarget:self action:@selector(select:) forControlEvents:UIControlEventTouchUpInside];
_selectButton.hidden = tzImagePickerVc.maxImagesCount == 1;
_selectButton.hidden = !tzImagePickerVc.showSelectBtn;
[_naviBar addSubview:_selectButton];
[_naviBar addSubview:_backButton];
......@@ -97,7 +100,7 @@
- (void)configBottomToolBar {
_toolBar = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.tz_height - 44, self.view.tz_width, 44)];
CGFloat rgb = 34 / 255.0;
static CGFloat rgb = 34 / 255.0;
_toolBar.backgroundColor = [UIColor colorWithRed:rgb green:rgb blue:rgb alpha:1.0];
_toolBar.alpha = 0.7;
......@@ -130,7 +133,7 @@
_okButton = [UIButton buttonWithType:UIButtonTypeCustom];
_okButton.frame = CGRectMake(self.view.tz_width - 44 - 12, 0, 44, 44);
_okButton.titleLabel.font = [UIFont systemFontOfSize:16];
[_okButton addTarget:self action:@selector(okButtonClick) forControlEvents:UIControlEventTouchUpInside];
[_okButton addTarget:self action:@selector(doneButtonClick) forControlEvents:UIControlEventTouchUpInside];
[_okButton setTitle:[NSBundle tz_localizedStringForKey:@"Done"] forState:UIControlStateNormal];
[_okButton setTitleColor:_tzImagePickerVc.oKButtonTitleColorNormal forState:UIControlStateNormal];
......@@ -175,6 +178,38 @@
[_collectionView registerClass:[TZPhotoPreviewCell class] forCellWithReuseIdentifier:@"TZPhotoPreviewCell"];
}
- (void)configCropView {
TZImagePickerController *_tzImagePickerVc = (TZImagePickerController *)self.navigationController;
if (!_tzImagePickerVc.showSelectBtn && _tzImagePickerVc.allowCrop) {
_cropView = [UIView new];
_cropView.userInteractionEnabled = NO;
static CGFloat rgb = 34 / 255.0;
_cropView.backgroundColor = [UIColor colorWithRed:rgb green:rgb blue:rgb alpha:1.0];
_cropView.alpha = 0.5;
_cropView.frame = self.view.bounds;
[self.view addSubview:_cropView];
[self overlayClipping];
}
}
- (void)overlayClipping {
TZImagePickerController *_tzImagePickerVc = (TZImagePickerController *)self.navigationController;
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
CGMutablePathRef path = CGPathCreateMutable();
// Left side of _cropView
CGPathAddRect(path, nil, CGRectMake(0, 0, _tzImagePickerVc.cropRect.origin.x, _cropView.tz_height));
// Right side of _cropView
CGPathAddRect(path, nil, CGRectMake(CGRectGetMaxX(_tzImagePickerVc.cropRect), 0, _cropView.tz_width - _tzImagePickerVc.cropRect.origin.x - _tzImagePickerVc.cropRect.size.width, _cropView.tz_height));
// Top side of _cropView
CGPathAddRect(path, nil, CGRectMake(0, 0, _cropView.tz_width, _tzImagePickerVc.cropRect.origin.y));
// Bottom side _cropView
CGPathAddRect(path, nil, CGRectMake(0, CGRectGetMaxY(_tzImagePickerVc.cropRect), _cropView.tz_width, _cropView.tz_height - _tzImagePickerVc.cropRect.origin.y + _tzImagePickerVc.cropRect.size.height));
maskLayer.path = path;
_cropView.layer.mask = maskLayer;
CGPathRelease(path);
}
#pragma mark - Click Event
- (void)select:(UIButton *)selectButton {
......@@ -247,18 +282,26 @@
}
}
- (void)okButtonClick {
- (void)doneButtonClick {
TZImagePickerController *_tzImagePickerVc = (TZImagePickerController *)self.navigationController;
// 如果没有选中过照片 点击确定时选中当前预览的照片
if (_tzImagePickerVc.selectedModels.count == 0 && _tzImagePickerVc.minImagesCount <= 0) {
TZAssetModel *model = _models[_currentIndex];
[_tzImagePickerVc.selectedModels addObject:model];
}
if (self.okButtonClickBlock) {
self.okButtonClickBlock(_isSelectOriginalPhoto);
if (_tzImagePickerVc.allowCrop) { // 裁剪状态
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:_currentIndex inSection:0];
TZPhotoPreviewCell *cell = (TZPhotoPreviewCell *)[_collectionView cellForItemAtIndexPath:indexPath];
UIImage *cropedImage = [self cropImageView:cell.imageView toRect:_tzImagePickerVc.cropRect zoomScale:cell.scrollView.zoomScale];
if (self.doneButtonClickBlockCropMode) {
TZAssetModel *model = _models[_currentIndex];
self.doneButtonClickBlockCropMode(cropedImage,model.asset);
}
} else if (self.doneButtonClickBlock) { // 非裁剪状态
self.doneButtonClickBlock(_isSelectOriginalPhoto);
}
if (self.okButtonClickBlockWithPreviewType) {
self.okButtonClickBlockWithPreviewType(self.photos,_tzImagePickerVc.selectedAssets,self.isSelectOriginalPhoto);
if (self.doneButtonClickBlockWithPreviewType) {
self.doneButtonClickBlockWithPreviewType(self.photos,_tzImagePickerVc.selectedAssets,self.isSelectOriginalPhoto);
}
}
......@@ -271,7 +314,7 @@
if (!_selectButton.isSelected) {
// 如果当前已选择照片张数 < 最大可选张数 && 最大可选张数大于1,就选中该张图
TZImagePickerController *_tzImagePickerVc = (TZImagePickerController *)self.navigationController;
if (_tzImagePickerVc.selectedModels.count < _tzImagePickerVc.maxImagesCount && _tzImagePickerVc.maxImagesCount > 1) {
if (_tzImagePickerVc.selectedModels.count < _tzImagePickerVc.maxImagesCount && _tzImagePickerVc.showSelectBtn) {
[self select:_selectButton];
}
}
......@@ -286,7 +329,7 @@
NSInteger currentIndex = offSetWidth / (self.view.tz_width + 20);
if (_currentIndex != currentIndex) {
if (currentIndex < _models.count && _currentIndex != currentIndex) {
_currentIndex = currentIndex;
[self refreshNaviBarAndBottomBarState];
}
......@@ -301,7 +344,9 @@
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
TZPhotoPreviewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TZPhotoPreviewCell" forIndexPath:indexPath];
cell.model = _models[indexPath.row];
TZImagePickerController *_tzImagePickerVc = (TZImagePickerController *)self.navigationController;
cell.cropRect = _tzImagePickerVc.cropRect;
cell.allowCrop = _tzImagePickerVc.allowCrop;
if (!cell.singleTapGestureBlock) {
__block BOOL _weakIsHideNaviBar = _isHideNaviBar;
__weak typeof(_naviBar) weakNaviBar = _naviBar;
......@@ -358,9 +403,9 @@
}
}
// 让宽度/高度小于 最小可选照片尺寸 的图片不能选中
_okButton.hidden = NO;
_selectButton.hidden = _tzImagePickerVc.maxImagesCount == 1;
_selectButton.hidden = !_tzImagePickerVc.showSelectBtn;
// 让宽度/高度小于 最小可选照片尺寸 的图片不能选中
if (![[TZImageManager manager] isPhotoSelectableWithAsset:model.asset]) {
_numberLable.hidden = YES;
_numberImageView.hidden = YES;
......@@ -377,4 +422,61 @@
}];
}
#pragma mark - Crop
- (UIImage *)cropImageView:(UIImageView *)imageView toRect:(CGRect)rect zoomScale:(double)zoomScale {
CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformScale(transform, zoomScale, zoomScale);
CGImageRef imageRef = [self newTransformedImage:transform
sourceImage:imageView.image.CGImage
sourceSize:imageView.image.size
outputWidth:imageView.image.size.width
cropSize:rect.size
imageViewSize:imageView.frame.size];
UIImage *cropedImage = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return cropedImage;
}
- (CGImageRef)newTransformedImage:(CGAffineTransform)transform sourceImage:(CGImageRef)sourceImage sourceSize:(CGSize)sourceSize outputWidth:(CGFloat)outputWidth cropSize:(CGSize)cropSize imageViewSize:(CGSize)imageViewSize {
CGImageRef source = [self newScaledImage:sourceImage toSize:sourceSize];
CGFloat aspect = cropSize.height/cropSize.width;
CGSize outputSize = CGSizeMake(outputWidth, outputWidth*aspect);
CGContextRef context = CGBitmapContextCreate(NULL, outputSize.width, outputSize.height, CGImageGetBitsPerComponent(source), 0, CGImageGetColorSpace(source), CGImageGetBitmapInfo(source));
CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]);
CGContextFillRect(context, CGRectMake(0, 0, outputSize.width, outputSize.height));
CGAffineTransform uiCoords = CGAffineTransformMakeScale(outputSize.width / cropSize.width, outputSize.height / cropSize.height);
uiCoords = CGAffineTransformTranslate(uiCoords, cropSize.width/2.0, cropSize.height / 2.0);
uiCoords = CGAffineTransformScale(uiCoords, 1.0, -1.0);
CGContextConcatCTM(context, uiCoords);
CGContextConcatCTM(context, transform);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextDrawImage(context, CGRectMake(-imageViewSize.width/2.0, -imageViewSize.height/2.0, imageViewSize.width, imageViewSize.height), source);
CGImageRef resultRef = CGBitmapContextCreateImage(context);
CGContextRelease(context);
CGImageRelease(source);
return resultRef;
}
- (CGImageRef)newScaledImage:(CGImageRef)source toSize:(CGSize)size {
CGSize srcSize = size;
CGColorSpaceRef rgbColorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, size.width, size.height, 8, 0, rgbColorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(rgbColorSpace);
CGContextSetInterpolationQuality(context, kCGInterpolationNone);
CGContextTranslateCTM(context, size.width/2, size.height/2);
CGContextDrawImage(context, CGRectMake(-srcSize.width/2, -srcSize.height/2, srcSize.width, srcSize.height), source);
CGImageRef resultRef = CGBitmapContextCreateImage(context);
CGContextRelease(context);
return resultRef;
}
@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