Skip to content

Commit

Permalink
Merge pull request TimOliver#49 from trramsiq/master
Browse files Browse the repository at this point in the history
Refactored clockwisebutton code seemed to have broken clampButtonHidden code
  • Loading branch information
TimOliver committed Jan 25, 2016
2 parents 1eef675 + a219bb4 commit ec421c6
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 52 deletions.
6 changes: 0 additions & 6 deletions TOCropViewController/TOCropViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
10 changes: 0 additions & 10 deletions TOCropViewController/TOCropViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -653,14 +653,4 @@ - (TOCropToolbar *)toolbar {
return _toolbar;
}

- (void)setShowClockwiseRotationButton:(BOOL)showClockwiseRotationButton
{
self.toolbar.showClockwiseRotationButton = showClockwiseRotationButton;
}

- (BOOL)showClockwiseRotationButton
{
return self.toolbar.showClockwiseRotationButton;
}

@end
7 changes: 3 additions & 4 deletions TOCropViewController/Views/TOCropToolbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,15 @@
@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;

/* Done button frame for popover controllers */
@property (nonatomic, readonly) CGRect doneButtonFrame;

/* Show the clockwise rotation button */
@property (nonatomic, assign) BOOL showClockwiseRotationButton;

@end
61 changes: 31 additions & 30 deletions TOCropViewController/Views/TOCropToolbar.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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];
}

Expand Down Expand Up @@ -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];
}

Expand Down
5 changes: 3 additions & 2 deletions TOCropViewControllerExample/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ - (void)imagePickerController:(UIImagePickerController *)picker didFinishPicking
// 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];
}];
Expand Down

0 comments on commit ec421c6

Please sign in to comment.