Skip to content

Instantly share code, notes, and snippets.

@zmcartor
Created September 9, 2014 17:25
Show Gist options
  • Save zmcartor/857c43c821cfcf75e555 to your computer and use it in GitHub Desktop.
Save zmcartor/857c43c821cfcf75e555 to your computer and use it in GitHub Desktop.
Zoom Scrollview
- (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