Skip to content

Commit

Permalink
Merge pull request #534 from yhkaplan/zoom-out-on-reset-aspect-ratio
Browse files Browse the repository at this point in the history
Prevent from steadily zooming in when cycling between alternate aspectRatios and original
  • Loading branch information
TimOliver authored Apr 6, 2024
2 parents 9f0202a + d0bb8fc commit e47dd62
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Objective-C/TOCropViewController/Views/TOCropView.m
Original file line number Diff line number Diff line change
Expand Up @@ -1403,9 +1403,12 @@ - (void)setAspectRatio:(CGSize)aspectRatio animated:(BOOL)animated
return;
}

BOOL zoomOut = NO;

// Passing in an empty size will revert back to the image aspect ratio
if (aspectRatio.width < FLT_EPSILON && aspectRatio.height < FLT_EPSILON) {
aspectRatio = (CGSize){self.imageSize.width, self.imageSize.height};
zoomOut = YES; // Prevent from steadily zooming in when cycling between alternate aspectRatios and original
}

CGRect boundsFrame = self.contentBounds;
Expand All @@ -1418,7 +1421,6 @@ - (void)setAspectRatio:(CGSize)aspectRatio animated:(BOOL)animated
else
cropBoxIsPortrait = aspectRatio.width < aspectRatio.height;

BOOL zoomOut = NO;
if (cropBoxIsPortrait) {
CGFloat newWidth = floorf(cropBoxFrame.size.height * (aspectRatio.width/aspectRatio.height));
CGFloat delta = cropBoxFrame.size.width - newWidth;
Expand Down

0 comments on commit e47dd62

Please sign in to comment.