I have a view that has been created in Interface Builder and configured to resize according to the orientation. If the view is created and added to the display while the application is in portrait mode everything works perfectly. I can then rotate the device/simulator and the view resizes as I would expect. But, if the view is added when the app is in landscape mode it does not resize correctly. The view is created and sized as if the app is still in portrait mode. The view is added with the following code:
self.viewController = [[MyViewController alloc] initWithNibName:nibName bundle:bundle];
[self addSubview:self.viewController.view];
Nothing magical happening here. Additionally, the view controller specifies:
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
Again, it works as expected as long as the view is added while in portrait mode. I've tried several different things including manually setting the autoresizingMask property on the view, calling setNeedsLayout, and calling layoutIfNeeded, but nothing seems to be working. I am able to manually set the width and height of the frame to force the view to resize, but this breaks the dynamic nature of the view. For example, if I manually set the width the height doesn't adjust as the content doesn't re-layout.
Any ideas?