I have an interesting problem. I have one UIScrollView and inside there is only one UIImageView with an image. I need this for zooming and panning. OK. When I click the button, I want to replace the image in the UIImageView (which is in the UIScrollView, like the one mentioned) with the next line.
So far I have done this:
self.imageView = nil; self.imageView = [[UIImageView alloc] initWithImage:nextImage];
The reason that I always set self.imageView to nil is because if I do not do this, then the next scaling is scaled or scaled like the previous one.
But I do not think this is a great solution for memory efficiency.
Is there any other way to set a new image in UIImageView with the βresetβ option for scaling, scaling, etc. ??
UPDATE: Code that still doesn't 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 realized what I'm doing wrong. I did not reset the minimum scale scale.
[self.scrollView setMinimumZoomScale:1.0]
Now it works!
Borut tomazin
source share