Skip to content

Instantly share code, notes, and snippets.

@jessedc
Created February 11, 2013 05:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jessedc/4752902 to your computer and use it in GitHub Desktop.
Save jessedc/4752902 to your computer and use it in GitHub Desktop.
- (void)scrollViewDidZoom:(UIScrollView *)scrollView
{
[self updateZoomableViewCenter:scrollView];
}
- (void)updateZoomableViewCenter:(UIScrollView *)scrollView
{
CGSize scrollViewSize = scrollView.bounds.size;
CGSize contentSize = scrollView.contentSize;
CGFloat offsetX = (scrollViewSize.width > contentSize.width) ? (scrollViewSize.width - contentSize.width) / 2.f : 0.f;
CGFloat offsetY = (scrollViewSize.height > contentSize.height) ? (scrollViewSize.height - contentSize.height) / 2.f : 0.f;
UIView *zoomableView = [scrollView.delegate viewForZoomingInScrollView:scrollView];
zoomableView.center = CGPointMake(contentSize.width / 2.f + offsetX, contentSize.height / 2.f + offsetY);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment