I’m trying to make a basic proof of concept app. It uses UIScrollView with an UIImageView inside of it.
I set the image then set the contentSize of the UIScrollView but I still can’t seem to scroll, it always bounces back to the start. Does anyone have any idea what I might be missing?
PS. Zooming works fine.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.picture setImage:nil];
[self.picture setImage:self.image];
self.scroll.contentSize = self.picture.frame.size;
}
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
{
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return self.picture;
}
Hi everyone ok, I’ve figured out what the problem was other then the fix below. It works as soon as i turn off the Autolayout option in storyboard.
When you set the image on a
UIImageView, the frame of it does not update to the size of the new image. What you’ll want to do is call the following to update the frame frame ofpictureto match the size of the image.On a side note, you dont need to set the image on nil on the imageView before changing it.