2

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?

enter image description here

invalidArgument
  • 2,289
  • 4
  • 24
  • 35
  • I finally took another direction. This problem didn't occur when the user rotate his device in the ViewController of the map (refer to exemple in OP). So I add a view with an icon (on top of the map) asking him to rotate his device. That view only goes away with device rotation... Doing so, the problem didn't reappear. This app I'm building is not intended for the AppStore, so I'm not concerned with guidelines. I'm sorry I don't have a better solution... – invalidArgument Oct 22 '14 at 19:14

0 Answers0