I am currently building an app for iPad where the view structure is completely different depending on the device orientation.
When the app is in portrait I am using the ECSlidingViewController library to support left and right sliding menu's (like facebook or path).
When the app is in landscape I need to display a splitviewcontroller so that the left hand menu is always visible.
Does anybody know of the best solution to this problem?
I have tried changing the RootViewController of the UIWindow when an orientation change is detected but this gave some very strange results....
There are several ways to do this. Some better than other, but mostly it will depends on the needs of your specific situation.
rootViewController
as you mentioned during rotation. UISplitViewController
and use a segue
to with replace
to replace the detailViewController
when rotating between portrait and landscape.addChildViewController:
and removeFromParentViewController:
Extremely crude example of choice 3.
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self.childViewControllers[0].view removeFromSuperView];
[self.childViewControllers[0] removeFromParentViewController];
if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
[self addChildViewController:portraitVC];
[self.view addSubview:portraitVC.view];
} else {
[self addChildViewController:landscapeVC];
[self.view addSubview:landscapeVC.view];
}
}
From what you've said, I'd guess option 3 would be the best fit. All this said though, I'm not entirely convinced you need to be switching view controllers, but I'm not familiar with ECSlidingViewController
and what it offers so I'm can't be certain.