Skip to content

Commit eb32fb1

Browse files
committed
Disable rotation buttons during animation
1 parent 8436bc9 commit eb32fb1

File tree

5 files changed

+33
-10
lines changed

5 files changed

+33
-10
lines changed

Objective-C/TOCropViewController/TOCropViewController.m

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,12 +732,18 @@ - (void)setAspectRatioPreset:(TOCropViewControllerAspectRatioPreset)aspectRatioP
732732

733733
- (void)rotateCropViewClockwise
734734
{
735-
[self.cropView rotateImageNinetyDegreesAnimated:YES clockwise:YES];
735+
self.toolbar.disableRotationButtons = YES;
736+
[self.cropView rotateImageNinetyDegreesAnimated:YES clockwise:YES completion:^(BOOL success) {
737+
self.toolbar.disableRotationButtons = NO;
738+
}];
736739
}
737740

738741
- (void)rotateCropViewCounterclockwise
739742
{
740-
[self.cropView rotateImageNinetyDegreesAnimated:YES clockwise:NO];
743+
self.toolbar.disableRotationButtons = YES;
744+
[self.cropView rotateImageNinetyDegreesAnimated:YES clockwise:NO completion:^(BOOL success) {
745+
self.toolbar.disableRotationButtons = NO;
746+
}];
741747
}
742748

743749
#pragma mark - Crop View Delegates -

Objective-C/TOCropViewController/Views/TOCropToolbar.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ NS_ASSUME_NONNULL_BEGIN
6262
@property (nonatomic, strong, readonly) UIButton *clampButton;
6363
@property (nullable, nonatomic, strong, readonly) UIButton *rotateClockwiseButton;
6464

65+
/* Set the rotation buttons to be disabled while rotating is in progress */
66+
@property (nonatomic, assign) BOOL disableRotationButtons;
67+
6568
@property (nonatomic, readonly) UIButton *rotateButton; // Points to `rotateCounterClockwiseButton`
6669

6770
/* Button feedback handler blocks */

Objective-C/TOCropViewController/Views/TOCropToolbar.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,4 +754,14 @@ - (UIView *)visibleCancelButton
754754
return self.cancelTextButton;
755755
}
756756

757+
- (void)setDisableRotationButtons:(BOOL)disableRotationButtons
758+
{
759+
if (_disableRotationButtons == disableRotationButtons) {
760+
return;
761+
}
762+
_disableRotationButtons = disableRotationButtons;
763+
_rotateClockwiseButton.enabled = !disableRotationButtons;
764+
_rotateCounterclockwiseButton.enabled = !disableRotationButtons;
765+
}
766+
757767
@end

Objective-C/TOCropViewController/Views/TOCropView.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,15 +265,15 @@ The minimum croping aspect ratio. If set, user is prevented from setting croppin
265265
266266
@param animated Whether the transition is animated
267267
*/
268-
- (void)rotateImageNinetyDegreesAnimated:(BOOL)animated;
268+
- (void)rotateImageNinetyDegreesAnimated:(BOOL)animated completion:(nullable void(^)(BOOL completed))completionHandler;
269269

270270
/**
271271
Rotates the entire canvas to a 90-degree angle
272272
273273
@param animated Whether the transition is animated
274274
@param clockwise Whether the rotation is clockwise. Passing 'NO' means counterclockwise
275275
*/
276-
- (void)rotateImageNinetyDegreesAnimated:(BOOL)animated clockwise:(BOOL)clockwise;
276+
- (void)rotateImageNinetyDegreesAnimated:(BOOL)animated clockwise:(BOOL)clockwise completion:(nullable void(^)(BOOL completed))completionHandler;
277277

278278
/**
279279
Animate the grid overlay graphic to be visible

Objective-C/TOCropViewController/Views/TOCropView.m

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,12 +1218,12 @@ - (void)setAngle:(NSInteger)angle
12181218
// on direction
12191219
if (newAngle >= 0) {
12201220
while (labs(self.angle) != labs(newAngle)) {
1221-
[self rotateImageNinetyDegreesAnimated:NO clockwise:YES];
1221+
[self rotateImageNinetyDegreesAnimated:NO clockwise:YES completion:nil];
12221222
}
12231223
}
12241224
else {
12251225
while (-labs(self.angle) != -labs(newAngle)) {
1226-
[self rotateImageNinetyDegreesAnimated:NO clockwise:NO];
1226+
[self rotateImageNinetyDegreesAnimated:NO clockwise:NO completion:nil];
12271227
}
12281228
}
12291229
}
@@ -1503,12 +1503,12 @@ - (void)setAspectRatio:(CGSize)aspectRatio animated:(BOOL)animated
15031503
completion:nil];
15041504
}
15051505

1506-
- (void)rotateImageNinetyDegreesAnimated:(BOOL)animated
1506+
- (void)rotateImageNinetyDegreesAnimated:(BOOL)animated completion:(void(^)(BOOL completed))completionHandler
15071507
{
1508-
[self rotateImageNinetyDegreesAnimated:animated clockwise:NO];
1508+
[self rotateImageNinetyDegreesAnimated:animated clockwise:NO completion:completionHandler];
15091509
}
15101510

1511-
- (void)rotateImageNinetyDegreesAnimated:(BOOL)animated clockwise:(BOOL)clockwise
1511+
- (void)rotateImageNinetyDegreesAnimated:(BOOL)animated clockwise:(BOOL)clockwise completion:(void(^)(BOOL completed))completionHandler
15121512
{
15131513
//Only allow one rotation animation at a time
15141514
if (self.rotateAnimationInProgress)
@@ -1666,7 +1666,7 @@ - (void)rotateImageNinetyDegreesAnimated:(BOOL)animated clockwise:(BOOL)clockwis
16661666
} completion:^(BOOL complete) {
16671667
self.rotateAnimationInProgress = NO;
16681668
[snapshotView removeFromSuperview];
1669-
1669+
16701670
// If the aspect ratio lock is not enabled, allow a swap
16711671
// If the aspect ratio lock is on, allow a aspect ratio swap
16721672
// only if the allowDimensionSwap option is specified.
@@ -1677,6 +1677,10 @@ - (void)rotateImageNinetyDegreesAnimated:(BOOL)animated clockwise:(BOOL)clockwis
16771677
//This will animate the aspect ratio back to the desired locked ratio after the image is rotated.
16781678
[self setAspectRatio:self.aspectRatio animated:animated];
16791679
}
1680+
1681+
if (completionHandler) {
1682+
completionHandler(complete);
1683+
}
16801684
}];
16811685
}];
16821686
}

0 commit comments

Comments
 (0)