Skip to content

Commit

Permalink
[RSKImageCropper] [RSKImageCropViewController] Fix zooming to the spe…
Browse files Browse the repository at this point in the history
…cified area.
  • Loading branch information
ruslanskorb committed Apr 7, 2024
1 parent f36aab3 commit a97fb6c
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1083,17 +1083,10 @@ - (void)resetZoomScale;
});

it(@"zooms to a specific area of the image", ^{
CGRect rect = CGRectMake(100.0, 100.0, 400.0, 400.0);
CGRect rect = CGRectMake(196.0f, 290.0f, 60.0f, 60.0f);
[imageCropViewController zoomToRect:rect animated:NO];

UIScrollView *imageScrollView = imageCropViewController.imageScrollView;
CGRect visibleRect = CGRectMake(round(imageScrollView.contentOffset.x / imageScrollView.zoomScale),
round(imageScrollView.contentOffset.y / imageScrollView.zoomScale),
imageScrollView.bounds.size.width / imageScrollView.zoomScale,
imageScrollView.bounds.size.height / imageScrollView.zoomScale);

BOOL contains = CGRectContainsRect(visibleRect, rect);
expect(contains).to.beTruthy();
expect(imageCropViewController.view).to.haveValidSnapshot();
});

after(^{
Expand Down
Binary file added ...eCropViewControllerSpec/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion RSKImageCropper/RSKImageCropViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ NS_SWIFT_UI_ACTOR
/**
Zooms to a specific area of the image so that it is visible.
@param rect A rectangle defining an area of the image.
@param rect A rectangle defining an area of the image. The rectangle should be in the coordinate space of the image view controller's view.
@param animated YES if the scrolling should be animated, NO if it should be immediate.
*/
- (void)zoomToRect:(CGRect)rect animated:(BOOL)animated;
Expand Down
2 changes: 1 addition & 1 deletion RSKImageCropper/RSKImageCropViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ - (void)handleRotation:(UIRotationGestureRecognizer *)gestureRecognizer

- (void)zoomToRect:(CGRect)rect animated:(BOOL)animated
{
[self.imageScrollView zoomToRect:rect animated:animated];
[self.imageScrollView zoomToRect:[self.imageScrollView convertRect:rect fromView:self.view] animated:animated];
}

#pragma mark - Public
Expand Down

0 comments on commit a97fb6c

Please sign in to comment.