I have an interesting problem. I have one UIScrollView and inside only one UIImageView with image. I need this for zooming and panning. Ok. On a button touch I want to replace image within UIImageView (which is within UIScrollView, like a mentioned) with the next one in line.
So far I've done this like that:
self.imageView = nil;
self.imageView = [[UIImageView alloc] initWithImage:nextImage];
The reason that I always set self.imageView
to nil is that if I don't do that than the next image is scaled or zoomed like the previous one was.
But I don't think thats fine solution for memory efficiency.
Is there any other way to set new image on UIImageView with "reset" option for zooming, scale, etc... ?
UPDATE: The code that still does not work:
[self.scrollView setZoomScale:1.0];
[self.imageView setImage:photoImage];
[self.imageView setFrame:rect];
[self.scrollView setContentSize:[self.imageView frame].size];
CGFloat minZoomScale = [self.scrollView frame].size.width / [self.imageView frame].size.width;
if (minZoomScale < [self.scrollView frame].size.height / [self.imageView frame].size.height) {
minZoomScale = [self.scrollView frame].size.height / [self.imageView frame].size.height;
}
[self.scrollView setMinimumZoomScale:minZoomScale];
[self.scrollView setZoomScale:[self.scrollView minimumZoomScale]];
UPDATE 2 Just figured out what I was doing wrong. I did not reset the minimum zoom scale.
[self.scrollView setMinimumZoomScale:1.0];
Now it works!