Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 6 auto rotation issue - supportedInterfaceOrientations return value not respected

I've got an app where I have a UINavigationController subclass as my rootViewController. I've got a UITableViewController that lets the user edit some settings, it should always be in portrait mode. My app also needs to support all other orientations after I push a MoviePlayer component onto the navigation controller.

The UITableViewController subclass has this implementation of supportedInterfaceOrientations:

- (NSUInteger)supportedInterfaceOrientations {
    LLog();
    return UIInterfaceOrientationMaskPortrait;
}

The logging command tells me that this gets actually called.

The problem is that the return value is not respected, i.e. the screen turns to landscape orientation when I turn the device.

What can I do to make the settings view always show in portrait but allow orientation changes for the video viewer?

More information: my UINavigationController subclass doesn't override shouldAutorotate or supportedInterfaceOrientations. I haven't implemented

   - (NSUInteger)application:(UIApplication *)application 

supportedInterfaceOrientationsForWindow:(UIWindow *)window

method in my AppDelegate and I have enabled all orientations in the target summary.

like image 315
flovdu Avatar asked Sep 23 '12 15:09

flovdu


2 Answers

I had issue that some ViewControllers in the navigation stack support all the orientations, some only portrait, but UINavigation controller was returning all app supported orientations, this little hack helped me.

@implementation UINavigationController (iOS6OrientationFix)

-(NSUInteger) supportedInterfaceOrientations {
    return [self.topViewController supportedInterfaceOrientations];
}

@end
like image 102
Mindaugas Avatar answered Oct 11 '22 19:10

Mindaugas


You also need to add:

- (BOOL)shouldAutorotate {
    return NO;
}

and set the supported rotations for the root view controller in the app plist file to only portrait.

like image 30
Sverrisson Avatar answered Oct 11 '22 18:10

Sverrisson