So I have the following hierarchy:
UINavigationController –> RootViewController (UIViewController) –> UITableViewController –> DetailViewController (UIViewController)
I want to lock the orientation on RootViewController to Portrait only, but leave all orientations for the rest view controllers.
If I put this to subclassed UINavigationController:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
All view controllers are then locked to portrait.
My question is, is there a way to lock only RootViewController to Portrait, but leave all options for other view controllers?
check the link here for fixing autorotation in iOS 6 and set orientation support per view basis: http://www.disalvotech.com/blog/app-development/iphone/ios-6-rotation-solution/
Here is what you could do:
Create a custom navigation controller that is a subclass of
UINavigationController, in your .m file:In your
AppDelegate.h,and in
AppDelegate.m,in your rootViewController, for whatever the event push the second view controller, do this:
in your each view controller, add
for iOS 6, you can set each view controller whatever the orientation support you want individually.
for iOS 5 and below, you can set
All the credits goes to John DiSalvo who wrote the sample app in the link.
Hope this helps.