I have a UINavigationController
where all UIViewController
in the stack are portrait, except the last one, which is landscape. My current implementation shows the last view controller in portrait on push, but I can rotate to landscape, and the, cannot rotate back to portrait. How can I force the rotation to landscape when the view is pushed ?
My UINavigationController
subclass :
@interface RotationViewController : UINavigationController
@end
@implementation RotationViewController
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
if (self.topViewController.class == [LoadingViewController class])
{
return UIInterfaceOrientationMaskLandscape;
}
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
if (self.topViewController.class == [LoadingViewController class])
{
return UIInterfaceOrientationLandscapeLeft;
}
return UIInterfaceOrientationPortrait;
}
@end
The view controller that I want landscape-only :
@implementation LoadingViewController
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
@end
Other view controllers don't implement any of these methods.