Skip to content

Commit

Permalink
允许设置横屏下的裁剪框尺寸cropRectLandscape
Browse files Browse the repository at this point in the history
  • Loading branch information
banchichen committed Jul 22, 2017
1 parent 4e381ea commit fe1a8db
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@
@property (nonatomic, assign) BOOL isStatusBarDefault;
/// 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; ///< 裁剪框的尺寸
@property (nonatomic, assign) BOOL needCircleCrop; ///< 需要圆形裁剪框
@property (nonatomic, assign) BOOL showSelectBtn; ///< 在单选模式下,照片列表页中,显示选择按钮,默认为NO
@property (nonatomic, assign) BOOL allowCrop; ///< 允许裁剪,默认为YES,showSelectBtn为NO才生效
@property (nonatomic, assign) CGRect cropRect; ///< 裁剪框的尺寸
@property (nonatomic, assign) CGRect cropRectPortrait; ///< 裁剪框的尺寸(竖屏)
@property (nonatomic, assign) CGRect cropRectLandscape; ///< 裁剪框的尺寸(横屏)
@property (nonatomic, assign) BOOL needCircleCrop; ///< 需要圆形裁剪框
@property (nonatomic, assign) NSInteger circleCropRadius; ///< 圆形裁剪框半径大小
@property (nonatomic, copy) void (^cropViewSettingBlock)(UIView *cropView); ///< 自定义裁剪框的其他属性

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ - (void)viewDidLoad {
self.navigationBar.tintColor = [UIColor whiteColor];
self.automaticallyAdjustsScrollViewInsets = NO;
if (!TZ_isGlobalHideStatusBar) [UIApplication sharedApplication].statusBarHidden = NO;
}
}
}

- (void)setNaviBgColor:(UIColor *)naviBgColor {
Expand Down Expand Up @@ -237,6 +237,9 @@ - (void)configDefaultSetting {

[self configDefaultImageName];
[self configDefaultBtnTitle];

CGFloat cropViewWH = MIN(self.view.tz_width, self.view.tz_height) / 3 * 2;
self.cropRect = CGRectMake((self.view.tz_width - cropViewWH) / 2, (self.view.tz_height - cropViewWH) / 2, cropViewWH, cropViewWH);
}

- (void)configDefaultImageName {
Expand Down Expand Up @@ -378,15 +381,14 @@ - (void)setAllowCrop:(BOOL)allowCrop {

- (void)setCircleCropRadius:(NSInteger)circleCropRadius {
_circleCropRadius = circleCropRadius;
_cropRect = CGRectMake(self.view.tz_width / 2 - circleCropRadius, self.view.tz_height / 2 - _circleCropRadius, _circleCropRadius * 2, _circleCropRadius * 2);
self.cropRect = CGRectMake(self.view.tz_width / 2 - circleCropRadius, self.view.tz_height / 2 - _circleCropRadius, _circleCropRadius * 2, _circleCropRadius * 2);
}

- (CGRect)cropRect {
if (_cropRect.size.width > 0) {
return _cropRect;
}
CGFloat cropViewWH = MIN(self.view.tz_width, self.view.tz_height) / 3 * 2;
return CGRectMake((self.view.tz_width - cropViewWH) / 2, (self.view.tz_height - cropViewWH) / 2, cropViewWH, cropViewWH);
- (void)setCropRect:(CGRect)cropRect {
_cropRect = cropRect;
_cropRectPortrait = cropRect;
CGFloat widthHeight = cropRect.size.width;
_cropRectLandscape = CGRectMake((self.view.tz_height - widthHeight) / 2, cropRect.origin.x, widthHeight, widthHeight);
}

- (void)setTimeout:(NSInteger)timeout {
Expand Down Expand Up @@ -503,21 +505,29 @@ - (void)dealloc {
#pragma mark - UIContentContainer

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
if (![UIApplication sharedApplication].statusBarHidden) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (iOS7Later && !TZ_isGlobalHideStatusBar) [UIApplication sharedApplication].statusBarHidden = NO;
});
[self willInterfaceOrientionChange];
if (size.width > size.height) {
_cropRect = _cropRectLandscape;
} else {
_cropRect = _cropRectPortrait;
}
self.cropRect = CGRectZero;
}

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (![UIApplication sharedApplication].statusBarHidden) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (iOS7Later && !TZ_isGlobalHideStatusBar) [UIApplication sharedApplication].statusBarHidden = NO;
});
[self willInterfaceOrientionChange];
if (toInterfaceOrientation >= 3) {
_cropRect = _cropRectLandscape;
} else {
_cropRect = _cropRectPortrait;
}
self.cropRect = CGRectZero;
}

- (void)willInterfaceOrientionChange {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.02 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (![UIApplication sharedApplication].statusBarHidden) {
if (iOS7Later && !TZ_isGlobalHideStatusBar) [UIApplication sharedApplication].statusBarHidden = NO;
}
});
}

#pragma mark - Layout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,7 @@ - (void)viewDidLayoutSubviews {
_divideLine.frame = CGRectMake(0, 0, self.view.tz_width, 1);

[TZImageManager manager].columnNumber = [TZImageManager manager].columnNumber;
if ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight) {
[self.collectionView reloadData];
}
[self.collectionView reloadData];
}

#pragma mark - Notification
Expand Down
13 changes: 10 additions & 3 deletions TZImagePickerController/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ - (void)pushTZImagePickerController {
TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:self.maxCountTF.text.integerValue columnNumber:self.columnNumberTF.text.integerValue delegate:self pushPhotoPickerVc:YES];
// imagePickerVc.navigationBar.translucent = NO;

#pragma mark - 四类个性化设置,这些参数都可以不传,此时会走默认设置
#pragma mark - 五类个性化设置,这些参数都可以不传,此时会走默认设置
imagePickerVc.isSelectOriginalPhoto = _isSelectOriginalPhoto;

if (self.maxCountTF.text.integerValue > 1) {
Expand Down Expand Up @@ -262,15 +262,22 @@ - (void)pushTZImagePickerController {
imagePickerVc.showSelectBtn = NO;
imagePickerVc.allowCrop = self.allowCropSwitch.isOn;
imagePickerVc.needCircleCrop = self.needCircleCropSwitch.isOn;
imagePickerVc.circleCropRadius = 100;
imagePickerVc.isStatusBarDefault = NO;
// 设置竖屏下的裁剪尺寸
NSInteger left = 30;
NSInteger widthHeight = self.view.tz_width - 2 * left;
NSInteger top = (self.view.tz_height - widthHeight) / 2;
imagePickerVc.cropRect = CGRectMake(left, top, widthHeight, widthHeight);
// 设置横屏下的裁剪尺寸
// imagePickerVc.cropRectLandscape = CGRectMake((self.view.tz_height - widthHeight) / 2, left, widthHeight, widthHeight);
/*
[imagePickerVc setCropViewSettingBlock:^(UIView *cropView) {
cropView.layer.borderColor = [UIColor redColor].CGColor;
cropView.layer.borderWidth = 2.0;
}];*/

//imagePickerVc.allowPreview = NO;

imagePickerVc.isStatusBarDefault = NO;
#pragma mark - 到这里为止

// You can get the photos by block, the same as by delegate.
Expand Down

0 comments on commit fe1a8db

Please sign in to comment.