My app has this main structure: UITabBarController, where each tab hosts a UINavigationController that pushes views according to user interaction. Almost all the app is portrait orientation only, except a few specific sections.
The behavior I want is to have landscape orientation when I push
one of the sections (let's say a map). In that map, the user can go back to portrait orientation. When he goes back in the main menu, he should go back to portrait orientation (landscape should not be allowed here). I don't mind if he is temporarily in landscape.
Here's some code from my UITabBarController subclass:
- (BOOL)shouldAutorotate
{
return [self.selectedViewController shouldAutorotate];
}
- (NSUInteger)supportedInterfaceOrientations
{
return [self.selectedViewController supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [self.selectedViewController preferredInterfaceOrientationForPresentation];
}
I use the same code in my UINavigationController, and in the specific menu, I have this:
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
- (BOOL)shouldAutorotate
{
if (!UIInterfaceOrientationIsPortrait([[UIDevice currentDevice] orientation]))
return NO;
return YES;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
The behavior works almost all the time. When the orientation of the menu is landscape and the user rotates his device, he goes back to portrait, but can't go back to landscape.
My issue is: once in a while, the status bar will rotate, but not the view controller. (see picture) Each time, shouldAutorotate
is called and returns the correct value (ie. it returns YES but does not autorotate).
I know this is stretching the SDK, but I'd love to make this work all the time. Any hints?