From bef2a6e6a80b5680880b3eb9bade70ec191ced7c Mon Sep 17 00:00:00 2001 From: Tristan Richard Date: Mon, 25 Jan 2016 10:39:56 +0100 Subject: [PATCH 1/2] Fix #48 and refactored clockwize rotation to match the rest of the library --- TOCropViewController/TOCropViewController.h | 6 -- TOCropViewController/TOCropViewController.m | 10 ---- TOCropViewController/Views/TOCropToolbar.h | 7 +-- TOCropViewController/Views/TOCropToolbar.m | 61 ++++++++++---------- TOCropViewControllerExample/ViewController.m | 5 ++ 5 files changed, 39 insertions(+), 50 deletions(-) diff --git a/TOCropViewController/TOCropViewController.h b/TOCropViewController/TOCropViewController.h index daadce17..ba0621b3 100644 --- a/TOCropViewController/TOCropViewController.h +++ b/TOCropViewController/TOCropViewController.h @@ -113,12 +113,6 @@ typedef NS_ENUM(NSInteger, TOCropViewControllerToolbarPosition) { */ @property (nonatomic, assign) TOCropViewControllerToolbarPosition toolbarPosition; -/** - Optionally show an additional button that will rotate the image clockwise, as opposed to counterclockwise. - Default is NO. - */ -@property (nonatomic, assign) BOOL showClockwiseRotationButton; - /** If true, the aspect ratio will be locked to the defaultAspectRatio. And, the aspect ratio button won't appear on the toolbar. */ diff --git a/TOCropViewController/TOCropViewController.m b/TOCropViewController/TOCropViewController.m index f7f7251d..82ef2d7b 100644 --- a/TOCropViewController/TOCropViewController.m +++ b/TOCropViewController/TOCropViewController.m @@ -653,14 +653,4 @@ - (TOCropToolbar *)toolbar { return _toolbar; } -- (void)setShowClockwiseRotationButton:(BOOL)showClockwiseRotationButton -{ - self.toolbar.showClockwiseRotationButton = showClockwiseRotationButton; -} - -- (BOOL)showClockwiseRotationButton -{ - return self.toolbar.showClockwiseRotationButton; -} - @end diff --git a/TOCropViewController/Views/TOCropToolbar.h b/TOCropViewController/Views/TOCropToolbar.h index 8bdd6e24..6b1857dc 100644 --- a/TOCropViewController/Views/TOCropToolbar.h +++ b/TOCropViewController/Views/TOCropToolbar.h @@ -52,8 +52,9 @@ @property (nonatomic, assign) BOOL clampButtonGlowing; @property (nonatomic, readonly) CGRect clampButtonFrame; -/* Disable the rotate button */ -@property (nonatomic, assign) BOOL rotateButtonHidden; +/* Rotate button settings */ +@property (nonatomic, assign) BOOL rotateCounterClockwiseButtonHidden; +@property (nonatomic, assign) BOOL rotateClockwiseButtonHidden; /* Enable the reset button */ @property (nonatomic, assign) BOOL resetButtonEnabled; @@ -61,7 +62,5 @@ /* Done button frame for popover controllers */ @property (nonatomic, readonly) CGRect doneButtonFrame; -/* Show the clockwise rotation button */ -@property (nonatomic, assign) BOOL showClockwiseRotationButton; @end diff --git a/TOCropViewController/Views/TOCropToolbar.m b/TOCropViewController/Views/TOCropToolbar.m index c8e0b8a9..95e72177 100644 --- a/TOCropViewController/Views/TOCropToolbar.m +++ b/TOCropViewController/Views/TOCropToolbar.m @@ -114,6 +114,13 @@ - (void)setup { [_clampButton addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside]; [self addSubview:_clampButton]; + _rotateClockwiseButton = [UIButton buttonWithType:UIButtonTypeSystem]; + _rotateClockwiseButton.contentMode = UIViewContentModeCenter; + _rotateClockwiseButton.tintColor = [UIColor whiteColor]; + [_rotateClockwiseButton setImage:[TOCropToolbar rotateCWImage] forState:UIControlStateNormal]; + [_rotateClockwiseButton addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside]; + [self addSubview:_rotateClockwiseButton]; + _rotateCounterclockwiseButton = [UIButton buttonWithType:UIButtonTypeSystem]; _rotateCounterclockwiseButton.contentMode = UIViewContentModeCenter; _rotateCounterclockwiseButton.tintColor = [UIColor whiteColor]; @@ -142,7 +149,8 @@ - (void)layoutSubviews self.doneIconButton.hidden = (!verticalLayout); self.doneTextButton.hidden = (verticalLayout); - self.rotateCounterclockwiseButton.hidden = self.rotateButtonHidden; +// self.rotateCounterclockwiseButton.hidden = self.rotateButtonHidden; + #if kTOCropToolbarShowButtonsContainerRectForDebugging static UIView *containerView = nil; @@ -201,16 +209,23 @@ - (void)layoutSubviews CGSize buttonSize = (CGSize){44.0f,44.0f}; - if (self.rotateButtonHidden) { - [self layoutToolbarButtons:@[self.resetButton, self.clampButton] withSameButtonSize:buttonSize inContainerRect:containerRect horizontally:YES]; + NSMutableArray *buttonsInOrderHorizontally = [NSMutableArray new]; + if (!self.rotateCounterClockwiseButtonHidden) { + [buttonsInOrderHorizontally addObject:self.rotateCounterclockwiseButton]; } - else { - NSMutableArray *buttonsInOrderHorizontally = [@[self.rotateCounterclockwiseButton, self.resetButton, self.clampButton] mutableCopy]; - if (self.rotateClockwiseButton) { - [buttonsInOrderHorizontally addObject:self.rotateClockwiseButton]; - } - [self layoutToolbarButtons:buttonsInOrderHorizontally withSameButtonSize:buttonSize inContainerRect:containerRect horizontally:YES]; + + [buttonsInOrderHorizontally addObject:self.resetButton]; + + if (!self.clampButtonHidden) { + [buttonsInOrderHorizontally addObject:self.clampButton]; + } + + if (!self.rotateClockwiseButtonHidden) { + [buttonsInOrderHorizontally addObject:self.rotateClockwiseButton]; } + + + [self layoutToolbarButtons:buttonsInOrderHorizontally withSameButtonSize:buttonSize inContainerRect:containerRect horizontally:YES]; } else { CGRect frame = CGRectZero; @@ -232,7 +247,7 @@ - (void)layoutSubviews CGSize buttonSize = (CGSize){44.0f,44.0f}; - if (self.rotateButtonHidden) { + if (self.rotateCounterClockwiseButtonHidden) { [self layoutToolbarButtons:@[self.resetButton, self.clampButton] withSameButtonSize:buttonSize inContainerRect:containerRect horizontally:NO]; } else { @@ -319,12 +334,12 @@ - (void)setClampButtonGlowing:(BOOL)clampButtonGlowing self.clampButton.tintColor = [UIColor whiteColor]; } -- (void)setRotateButtonHidden:(BOOL)rotateButtonHidden +- (void)setRotateCounterClockwiseButtonHidden:(BOOL)rotateButtonHidden { - if (_rotateButtonHidden == rotateButtonHidden) + if (_rotateCounterClockwiseButtonHidden == rotateButtonHidden) return; - _rotateButtonHidden = rotateButtonHidden; + _rotateCounterClockwiseButtonHidden = rotateButtonHidden; [self setNeedsLayout]; } @@ -538,27 +553,13 @@ + (UIImage *)clampImage #pragma mark - Accessors - -- (void)setShowClockwiseRotationButton:(BOOL)showClockwiseRotationButton +- (void)setRotateClockwiseButtonHidden:(BOOL)showClockwiseRotationButton { - if (_showClockwiseRotationButton == showClockwiseRotationButton) { + if (_rotateClockwiseButtonHidden == showClockwiseRotationButton) { return; } - _showClockwiseRotationButton = showClockwiseRotationButton; - - if (_showClockwiseRotationButton) { - _rotateClockwiseButton = [UIButton buttonWithType:UIButtonTypeSystem]; - _rotateClockwiseButton.contentMode = UIViewContentModeCenter; - _rotateClockwiseButton.tintColor = [UIColor whiteColor]; - [_rotateClockwiseButton setImage:[TOCropToolbar rotateCWImage] forState:UIControlStateNormal]; - [_rotateClockwiseButton addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside]; - [self addSubview:_rotateClockwiseButton]; - } - else { - [_rotateClockwiseButton removeFromSuperview]; - _rotateClockwiseButton = nil; - } - + _rotateClockwiseButtonHidden = showClockwiseRotationButton; [self setNeedsLayout]; } diff --git a/TOCropViewControllerExample/ViewController.m b/TOCropViewControllerExample/ViewController.m index 27e83250..cfe9e868 100644 --- a/TOCropViewControllerExample/ViewController.m +++ b/TOCropViewControllerExample/ViewController.m @@ -128,6 +128,11 @@ - (void)imagePickerController:(UIImagePickerController *)picker didFinishPicking self.image = image; TOCropViewController *cropController = [[TOCropViewController alloc] initWithImage:image]; cropController.delegate = self; +// cropController.toolbar.clampButtonHidden = true; +// cropController.showClockwiseRotationButton = true; + cropController.toolbar.rotateClockwiseButtonHidden = true; + cropController.toolbar.rotateCounterClockwiseButtonHidden = true; + // Uncomment this to place the toolbar at the top of the view controller // cropController.toolbarPosition = TOCropViewControllerToolbarPositionTop; From a219bb4aba06741f6c637d584ebb7bbfefac34aa Mon Sep 17 00:00:00 2001 From: Tristan Richard Date: Mon, 25 Jan 2016 10:42:09 +0100 Subject: [PATCH 2/2] Updated demo view controller with how to hide commands --- TOCropViewControllerExample/ViewController.m | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/TOCropViewControllerExample/ViewController.m b/TOCropViewControllerExample/ViewController.m index cfe9e868..03c93e5d 100644 --- a/TOCropViewControllerExample/ViewController.m +++ b/TOCropViewControllerExample/ViewController.m @@ -128,17 +128,13 @@ - (void)imagePickerController:(UIImagePickerController *)picker didFinishPicking self.image = image; TOCropViewController *cropController = [[TOCropViewController alloc] initWithImage:image]; cropController.delegate = self; -// cropController.toolbar.clampButtonHidden = true; -// cropController.showClockwiseRotationButton = true; - cropController.toolbar.rotateClockwiseButtonHidden = true; - cropController.toolbar.rotateCounterClockwiseButtonHidden = true; - // Uncomment this to place the toolbar at the top of the view controller // cropController.toolbarPosition = TOCropViewControllerToolbarPositionTop; - // Uncomment this to add an additional clockwise rotation button - // cropController.showClockwiseRotationButton = YES; + // Uncomment to hide rotation buttons +// cropController.toolbar.rotateClockwiseButtonHidden = true; +// cropController.toolbar.rotateCounterClockwiseButtonHidden = true; [self presentViewController:cropController animated:YES completion:nil]; }];