I am currently facing the conundrum that when I rotate my device, the view does not change its size. The view is a imageView embedded in a scroll view. The view controller is embedded in a navigation controller. Here’s core code for my view controller.
- (void)viewDidLoad
{
[super viewDidLoad];
[[self navigationItem] setTitle:self.imageTitle];
[self.imageView setImage:self.myImage];
self.scrollView.delegate = self;
self.scrollView.contentSize = self.imageView.image.size;
double scale = self.imageView.bounds.size.width * 1.0 / self.myImage.size.width;
if (scale > self.imageView.bounds.size.height * 1.0 / self.myImage.size.height)
scale = self.imageView.bounds.size.height * 1.0 / self.myImage.size.height;
self.imageView.frame = CGRectMake(0, 0, self.imageView.image.size.width,
self.imageView.image.size.height);
[self.scrollView setZoomScale:scale];
}
Typically some information about the view is not updated until later than viewDidLoad.
As prior to completion of viewDidLoad. The nib is not loaded completely. So you may not get the size and other details about it.
Moving the view size query to
viewWillAppearorviewDidAppearshould solve the issue.Hope this helps you.