I seem to be having difficulties with my iOS Application.
It's deployment target is iOS5.0, however I am using the iOS 6.0 SDK.
In my View Controller I have:
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationMaskPortrait;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}
This works fine when running in the iOS5 simulator. The view will not rotate to LandScape or upside down.
However, in the IOS6 Simulator (and on a Device), it will continue to rotate.
I have used NSLog
to check that -supportedInterfaceOrientations
does get called and it does, twice, however it still rotates to LandScape (right or left)
What am I doing wrong?
I've also extended the UINavigationController
(My Root View Controller) to include this:
@implementation UINavigationController (Rotation_IOS6)
-(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
@end
But with still no success.
Thanks.
Edit
As per matt's answer. I also needed to extend the UITabBarController with a similar implementation to my UINavigationController and that worked.
Hope this helps someone else.
Check your project settings and info.plist they have a higher priority than the app delegate. make sure that only the orientations you want are selected
If you don't want the app to ever rotate you can remove landscape from your supported interface orientations in your info.plist and that should do it.
Otherwise you need to tell your root view controller to look to its children for orientation information.
-Brandon
The problem could be that you have a navigation interface. Do you? If so, you need to subclass UINavigationController and use an instance of that subclass as your navigation controller. In that subclass, that is where you implement
supportedInterfaceOrientations
. So too for any parent view controller (e.g UITabBarController).The reason is that the iOS 6 way of thinking about rotation is completely different from iOS 5. Nothing you think you know from iOS 5 applies any more. In iOS 6 we start at the level of the application itself and work our way down by way of the app delegate to the root view controller or other full screen view controller (e.g. a presented view controller) and stop. A parent no longer consults its children.
Moreover, the application itself (by way of the info.plist or the app delegate) must list every orientation that any part of the application can ever assume; view controllers can only ask for a subset of those.
See the release notes:
http://developer.apple.com/library/ios/#releasenotes/General/RN-iOSSDK-6_0/_index.html
However, note that this sentence is a lie:
On the contrary, in iOS 6 the older autorotation methods are ignored completely; everybody gets the new autorotation behaviors. It is not "opt-in".