adit
adit

Reputation: 33674

issue with iOS 6 autorotation

I have a viewcontroller in which I wanted it to be presented only in portrait, so I did the following in iOS 6:

-(BOOL)shouldAutorotate
{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

however when I rotate the device, it still turns it to landscape. Any idea where else to check this? I put a break point and it hits supportedInterfaceOrientations, but it still rotates

Upvotes: 1

Views: 1051

Answers (3)

ehanna
ehanna

Reputation: 9

Make sure that your project settings and info.plist have only portrait orientation selected as they have a higher priority than the app delegate when checking for supported orientations

Upvotes: 0

Daniel
Daniel

Reputation: 23359

You should also provide the apps supported orientations in the app delegate:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
    return UIInterfaceOrientationMaskPortrait;
}

Make sure you add the root view controller properly (not adding it as a subview), but using the following:

[window setRootViewController:myVC];

Also if your view controller is inside a UINavigationController, you should use this category for the navigationcontroller:

@implementation UINavigationController (autorotate)

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait;
}

@end

In iOS 6, only the root view controller of the top most full screen controller is asked about rotation. This includes UINavigationController, this class does not ask it's view controllers, it responds directly. Apple now suggest subclassing UINavigationController to override supportedInterfaceOrientations's output.

Upvotes: 2

rooster117
rooster117

Reputation: 5552

Do you have a navigation controller? The way that iOS6 determines what can be autorotated has changed. It is correctly asking supportedInterfaceOrientations for your view controller but it is probably asking "shouldAutorotate" to another element in your navigation stack hierarchy and accepting that answer. If your navigationController/tabviewController returns yes to this question then it won't consult with your view controller.

Upvotes: 4

Related Questions