Guest User

Untitled

a guest
May 24th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1.  
  2. // call when zoom level or page size changes (i.e. after zooming or after rotation)
  3. - (void)updateContentInsetForPageScrollView:(UIScrollView *)pageScrollView {
  4. UIImageView *imageView = (UIImageView *) [pageScrollView viewWithTag:TAG_IMAGE_VIEW];
  5. CGFloat zoomScale = pageScrollView.zoomScale;
  6.  
  7. CGSize imageSize = imageView.bounds.size;
  8. CGSize zoomedImageSize = CGSizeMake(imageSize.width * zoomScale, imageSize.height * zoomScale);
  9. CGSize pageSize = pageScrollView.bounds.size;
  10.  
  11. UIEdgeInsets inset = UIEdgeInsetsZero;
  12. if (pageSize.width > zoomedImageSize.width) {
  13. inset.left = (pageSize.width - zoomedImageSize.width) / 2;
  14. inset.right = -inset.left;
  15. }
  16. if (pageSize.height > zoomedImageSize.height) {
  17. inset.top = (pageSize.height - zoomedImageSize.height) / 2;
  18. inset.bottom = -inset.top;
  19. }
  20. pageScrollView.contentInset = inset;
  21. }
  22.  
  23. -(void)scrollViewDidZoom:(UIScrollView *)pageScrollView {
  24. [self updateContentInsetForPageScrollView:pageScrollView];
  25. }
  26.  
  27. - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
  28. // loop through all pages, adjusting their sizes
  29. // and calling updateContentInsetForPageScrollView for each
  30. }
Add Comment
Please, Sign In to add comment