I'm hitting a problem getting a UIScrollView to update correctly in response to a change in the minimum zoom scale.
The scrollview has a UIImageView as a subview, and the image property of the UIImageView is set in response to the didFinishPickingMediaWithInfo method of UIPickerView:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *takenImage = [info objectForKey:UIImagePickerControllerOriginalImage];
[self.imageView setImage:takenImage];
[self.imageView setFrame:CGRectMake(self.imageView.frame.origin.x, self.imageView.frame.origin.y, takenImage.size.width, takenImage.size.height)];
[self.scrollView setContentSize:CGSizeMake(takenImage.size.width, takenImage.size.height)];
[self.scrollView setMinimumZoomScale:[self.scrollView frame].size.width / takenImage.size.width];
[self.scrollView setMaximumZoomScale:2.0];
[self.scrollView setZoomScale:[self.scrollView minimumZoomScale] animated:YES];
[self dismissModalViewControllerAnimated:YES];
}
This works correctly the first time an image is added using this method. However, if this method is triggered again - even to add the same image as the first time - the subsequent image is displayed at full size in the scrollView, and can't be zoomed out - only zoomed in.
I've dumped the contentSize
, zoomScale
, minimumZoomScale
and maximumZoomScale
of the scrollView to the log, and they are the same each time. The minimumZoomScale
is being calculated correctly each time.
It's as if the scrollView is being redrawn with a minimumZoomScale
of 1.0, ignoring the fact it's been explicitly set. Is there something obvious that I'm missing here?