My app starts with a root view controller. Its job is to display a splash screen until the app is ready. The splash screen is in a separate view controller (splashVC). When the app is ready, appDelegate calls a present method in the root view controller. From here, the root view controller adds another view controller (mainVC) as a child and then transitions to the new controller with
[splashVC willMoveToParentViewController:nil];
[self transitionFromViewController:splashVC
toViewController:mainVC
duration:0.5
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
[self.view addSubview:mainVC.view];
[splashVC.view removeFromSuperview];
}
completion:^(BOOL finished) {
[splashVC removeFromParentViewController];
}];
My issue is that if I start the app in landscape mode, then I see the Default.png load followed by my splash screen that is auto rotated to landscape. This all makes sense. But then, when the mainVC comes on the screen, its view seems to be stuck in the portrait orientation – the view does not extend all the way to the right border of the screen. The root view controller autoresizes fine – I added a background color to it so I can see that the mainVC does not completely cover it. I thought that this may be because the mainVC was not a child when the rotation occurred. So I then added the mainVC in the root view controller’s loadView method where the splashVC was added. I’m just trying to figure out why when the mainVC is displayed, it is not autoresizing. If I add the method –
willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
then I can see that the rotation occurs before the mainVC is loaded since this is never called in mainVC. I don’t want to hack in changing the size of the view. Any help on to how to handle this would be great. Perhaps I’m missing something in my containment but I am using the addChildViewController and didMoveToParentViewController methods to add my view controllers as children to the root view controller.
EDIT – I’ve notice that in mainVC’s initWithNibNamed… method the value of self.interfaceOrientation is portrait, but its viewDidLoad method the value is landscape. I’m not sure if there is a good way that I can account for this. It seems that the rotation happened while the nib was being loaded.
Thanks in advance.
To fix this added the second view controller as child while setting up the view controller instead of waiting until right before I present the view controller.