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?
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.
Does the second image have a different aspect ratio than the first? If so, look at UIImageView's contentMode
property.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.