I implemented a view controller that simply displays a single image and allows the user to pinch to enlarge / pan the image. It works great on iOS 7, but on iOS 8, the scroll view frame is different in size, and the end result is that the image is very encrypted on the iPhone and reduced too much on the iPad when working on iOS 8. This is due to the frame width the scroll is 600pt, which is its size in the storyboard (Universal Storyboard using size classes). But I have autodetection restrictions that must provide scroll stretching to fill the available space - there should be 768pt on the iPad. This applies to iOS 7, but not to iOS 8.
This is the setting: In the Builder interface, I have a UIViewController that contains a UIView that contains a UIScrollView with autorun restrictions ending, leading, lower and upper places for the supervisor. Then in viewDidLoad :
UIImage *image = [UIImage imageNamed:@"image"]; self.imageView = [[UIImageView alloc] initWithImage:image]; self.imageView.contentMode = UIViewContentModeScaleAspectFit; self.imageView.frame = CGRectMake(0, 0, self.imageView.image.size.width, self.imageView.image.size.height); [self.scrollView addSubview:self.imageView]; self.scrollView.contentSize = image.size; #warning Bug here - scroll view frame is 600pt on iOS 8 - should be 768 for iPad NSLog(@"scroll view frame wid: %f", self.scrollView.frame.size.width);
I found that if I put the same NSLog in viewDidAppear , the frame width would be correctly 768pt. I tried moving this code to viewWillAppear instead of viewDidLoad , but I get the same result - it's 600 in viewWillAppear . Thus, the scroll view is properly stretched to fill the display, but only after it appears on the screen. I need the correct frame size before the image appears on the screen so that I can calculate the correct minimum and maximum zoom values.
What can I do to fix this and make sure it works for iOS 7 and 8?
ios autolayout ios8 uiscrollview uiimageview
Joey
source share