Reputation: 3601
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.
Upvotes: 0
Views: 845
Reputation: 3601
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.
Upvotes: 0
Reputation: 116
ViewControllers only get updates to orientation when they are presented are part of a view hierarchy when it receives the message that the view has changed. (That message has already been sent out in this case) The exception to this is if you used the apple methods for navigation. Those correctly set up views when they get pushed/presented.
Try having a base navigation and using push and pop to switch between screens. Or if you really want to get rid of that one view controller you can call You can still animated them differently.
navigationController setViewControllers:(NSArray *) animated:(BOOL)
and pass in an array with your new view controller inside. If you set animated to NO you can just use that same animation block to do a custom one.
Upvotes: 1