I added three view controllers into navigation controller. The first and second view controller should support both orientation but third view controller only support for landscape mode. But when I navigate to the third view controller from second view controller in portrait mode, it is displayed in portrait mode. How can I rectify this one? I need third view controller to support only landscape orientation.
1 Answers
0
votes
This is an iOS 6 answer.
To make the UINavigationController honor the rotation preferences of its children, subclass it and override the following:
- (BOOL)shouldAutorotate
{
return self.topViewController.shouldAutorotate;
}
- (NSUInteger)supportedInterfaceOrientations
{
return self.topViewController.supportedInterfaceOrientations;
}
This works when creating a new UINavigationController and when popping back to earlier view controllers. More info here - ViewController in UINavigationController orientation change
To make it work when pushing new view controllers, add this to your subclass:
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[super pushViewController:viewController animated:animated];
UIViewController *viewController = [[UIViewController alloc] init];
[self presentViewController:viewController animated:NO completion:nil];
[self dismissViewControllerAnimated:NO completion:nil];
}
The transition is a bit unpleasant, but it gets the job done. More info here - Problem pushViewController from Landscape to Portrait