iOS 6 rotations: supportedInterfaceOrientations doesn´t work?
If your ViewController is a child of a UINavigationController or UITabBarController, then it is the parent that is your problem. You might need to subclass that parent view controller, just overriding those InterfaceOrientation methods as you've shown in your question
EDIT:
Example for portrait only TabBarController
@interface MyTabBarController : UITabBarController { } @end @implementation MyTabBarController // put your shouldAutorotateToInterfaceOrientation and other overrides here - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait); } - (NSUInteger)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskPortrait; } @end
Adding to CSmith's answer above, the following code in a UINavigationController subclass allows delegation to the top view controller in the way that I expected this to work in the first place:
- (BOOL)shouldAutorotate;{ return YES;}- (NSUInteger)supportedInterfaceOrientations{ if ([[self topViewController] respondsToSelector:@selector(supportedInterfaceOrientations)]) return [[self topViewController] supportedInterfaceOrientations]; else return [super supportedInterfaceOrientations];}
Here's another alternative to CSmith's approach.
If you want to replicate the pre-iOS 6 behaviour where all the views in the navigation stack / tab bar have to agree on an allowable set of orientations, put this in your subclass of UITabBarController
or UINavigationController
:
- (NSUInteger)supportedInterfaceOrientations{ NSUInteger orientations = [super supportedInterfaceOrientations]; for (UIViewController *controller in self.viewControllers) orientations = orientations & [controller supportedInterfaceOrientations]; return orientations;}