I have a UITabBarViewController
in portrait mode where I push a modalViewController
in landscape. The rotation changes to landscape when I push the modal, but when I dismiss it the orientation remains in landscape instead of reverting to portrait.
Code:
a CustomUINavigationController
for the landscape mode:
- (BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
- (NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
the uitabbarcontroller
- (BOOL)shouldAutorotate
{
if ([self inModal]) {
UINavigationController *nav = (UINavigationController *)self.modalViewController;
return [[nav.viewControllers lastObject] shouldAutorotate];
} else {
return NO;
}
}
-(NSUInteger)supportedInterfaceOrientations
{
if ([self inModal]) {
UINavigationController *nav = (UINavigationController *)self.modalViewController;
return [[nav.viewControllers lastObject] supportedInterfaceOrientations];
} else {
return UIInterfaceOrientationPortrait;
}
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
if ([self inModal]) {
UINavigationController *nav = (UINavigationController *)self.modalViewController;
return [[nav.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
} else {
return UIInterfaceOrientationPortrait;
}
}
- (BOOL)inModal
{
if (self.modalViewController && [self.modalViewController isKindOfClass:[UINavigationController class]]) {
return YES;
} else {
return NO;
}
}
If I set shouldRotate to YES I get an error: * Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES. Even though I have set the two orientations in UISupportedDeviceOrientations.