Created
September 9, 2014 17:25
-
-
Save zmcartor/857c43c821cfcf75e555 to your computer and use it in GitHub Desktop.
Zoom Scrollview
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)scrollViewDoubleTapped:(UITapGestureRecognizer*)recognizer { | |
// 1 | |
CGPoint pointInView = [recognizer locationInView:self.imageView]; | |
// 2 | |
CGFloat newZoomScale = self.scrollView.zoomScale * 1.5f; | |
newZoomScale = MIN(newZoomScale, self.scrollView.maximumZoomScale); | |
// 3 | |
CGSize scrollViewSize = self.scrollView.bounds.size; | |
CGFloat w = scrollViewSize.width / newZoomScale; | |
CGFloat h = scrollViewSize.height / newZoomScale; | |
CGFloat x = pointInView.x - (w / 2.0f); | |
CGFloat y = pointInView.y - (h / 2.0f); | |
CGRect rectToZoomTo = CGRectMake(x, y, w, h); | |
// 4 | |
[self.scrollView zoomToRect:rectToZoomTo animated:YES]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment