0

I have a screen-sized UIScrollView holding an identically sized UIImageView.

I have an image set inside of the UIImageView with AspectFit, so with a wider image, there are black bars on the top and bottom. This is as expected when zoomed out.

Double tapping the screen forces a [self.scrollView setZoomScale:self.scrollView.maximumZoomScale animated:YES]; The problem with this is that on images like the one mentioned above, I'm able to pan far beyond the edges of the photo.

I assume this is because I return imageView; in (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView and the imageView height is taller than the image, so I'm able to pan to the top and bottom of the imageView, ignoring its contents.

So, how do I limit panning the scrollview to the bounds of the image?

Adama
  • 1,101
  • 8
  • 26

2 Answers2

0

U need to use this: Emulating aspect-fit behaviour using AutoLayout constraints in Xcode 6

Aspect fit on Autolayout. Then You need add aspect ration constraint when loading image, if images are different size. U can get one error, image after zoom sticks to right edge. Still can't solve it.

Community
  • 1
  • 1
palusik
  • 111
  • 11
0

Just set the content size of scrollview to the size of image just by this code:

scrollView.contentSize = [scrollView imageView].image.size;

Note that you should do this at the time you set image for your scrollview imageView.