[I have searched Stackoverflow and tried the various solutions/suggestions but haven't yet resolved this. So appreciate if someone can point what am I missing here.]
I have a custom UITabBarController with multiple tabs. Each is a UINavigationController. One of them ViewX is a custom UINavigationController.
I want the ViewX to not rotate to landscape (Only PortraitUp is supported). I was able to achieve that. However if I'm in the landscape mode on some other tab and tap on the tab with ViewX, I want it to rotate back to Portrait, but it stays in landscape.
The CustomUITabController has this code:
-(BOOL)shouldAutorotate
{
return [self.selectedViewController shouldAutorotate];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [self.selectedViewController preferredInterfaceOrientationForPresentation];
}
- (NSUInteger)supportedInterfaceOrientations
{
if (self.selectedViewController)
return [self.selectedViewController supportedInterfaceOrientations];
return UIInterfaceOrientationMaskPortrait;
}
The CustomUINavigationController has this implemented:
-(BOOL)shouldAutorotate
{
UIInterfaceOrientation interfaceOrientation = [UIApplication sharedApplication].statusBarOrientation;
return (interfaceOrientation != UIInterfaceOrientationPortrait);
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
I even tried this: This only rotates the Status bar to portrait but the view still remains in Landscape.
- (void)viewWillLayoutSubviews
{
UIInterfaceOrientation interfaceOrientation = [UIApplication sharedApplication].statusBarOrientation;
if (interfaceOrientation != UIInterfaceOrientationPortrait)
{
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
}
}