Search code examples
orientationios6uideviceorientation

iOS 6 orientation issues


I have an application which normally is a portrait app and only show landscape view for one UIViewController. It works fine until the new iOS 6 is released.

I really don't understand how orientation works in iOS 6. So I wrote a testing app. Here is what I did:

  • Set the orientation of the application to support all orientations.

enter image description here

  • I'm using story board. The rootViewController is embedded in UINavigationController which is in portrait.

enter image description here

  • The code in rootViewController:

    -(NSUInteger)supportedInterfaceOrientations

    {

    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;

}

  • When I clicked the Open bar button, I'll push another (SecondViewController) view controller which supposed to be in landscape mode:

    -(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight; }

Although this method is called correctly, the second view controller is always also in portrait mode.

Can anybody give me some suggestions? Thanks


Solution

  • Here is my solution:

    In second view controller's viewDidLoad:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        UIViewController *viewController = [[UIViewController alloc] init];
        [self presentViewController:viewController animated:NO completion:^{
            [viewController dismissViewControllerAnimated:NO completion:nil];
        }];
    }
    

    This will force the second view to rotate to landscape orientation which solved my problem. And it works for iOS 5 and 6.