tags:

views:

294

answers:

2

I have a UIScrollView with a UIImageView subview created in IB. The first time I create a UIImage and set it to be the image in the UIImageView all works fine. If I create a new UIImage and set it to be the image in the UIImageView the image is offset by some (seemingly) random offset.

How can I make this work?

+1  A: 

Does the second image have a different aspect ratio than the first? If so, look at UIImageView's contentMode property.

Ole Begemann
No. This still happens even if it is the same image (I am loading images from disk, I duped the image so it is exactly the same image.
zaph
+2  A: 

It seems that this should be as easy as setting a new image but it seems that as a minimum the following is necessary:

imageScrollView.transform = CGAffineTransformIdentity;
imageScrollView.contentOffset = CGPointZero;
imageScrollView.contentSize = self.imageScrollView.frame.size;

[imageScrollView removeFromSuperview];
imageView = [[TapDetectingImageView alloc] initWithImage:newImage];

[imageScrollView addSubview: imageView];

Where imageScrollView, imageScrollView and newImage are previously instantiated.

zaph
Don't you mean `[imageView removeFromSuperview]` on line 5?
Frank Schmitt