In an app i\'m maintaining there\'s a rotate that should happen in portrait and portraitupsidedown mode. (all the rotation are enabled in the summary panel.)
My application targeted from IOS 5. I used shouldAutorotateToInterfaceOrientation method (by default) for IOS 5 device. And categories UINavigationController to handle the orientation for IOS 6.
#import "UINavigationController+Rotation_IOS6.h"
@implementation UINavigationController (Rotation_IOS6)
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
if([self.visibleViewController isMemberOfClass:NSClassFromString(@"SampleViewController")])
{
return UIInterfaceOrientationMaskLandscape | UIInterfaceOrientationMaskPortraitUpsideDown | UIInterfaceOrientationMaskPortrait;
}
return UIInterfaceOrientationPortrait;
}
@end
From Apple's iOS 6 SDK Release Notes:
Autorotation is changing in iOS 6. In iOS 6, the
shouldAutorotateToInterfaceOrientation:
method ofUIViewController
is deprecated. In its place, you should use thesupportedInterfaceOrientationsForWindow:
andshouldAutorotate
methods.More responsibility is moving to the app and the app delegate. Now, iOS containers (such as
UINavigationController
) do not consult their children to determine whether they should autorotate. By default, an app and a view controller’s supported interface orientations are set toUIInterfaceOrientationMaskAll
for the iPad idiom andUIInterfaceOrientationMaskAllButUpsideDown
for the iPhone idiom.A view controller’s supported interface orientations can change over time—even an app’s supported interface orientations can change over time. The system asks the top-most full-screen view controller (typically the root view controller) for its supported interface orientations whenever the device rotates or whenever a view controller is presented with the full-screen modal presentation style. Moreover, the supported orientations are retrieved only if this view controller returns
YES
from itsshouldAutorotate
method. The system intersects the view controller’s supported orientations with the app’s supported orientations (as determined by the Info.plist file or the app delegate’sapplication:supportedInterfaceOrientationsForWindow:
method) to determine whether to rotate.The system determines whether an orientation is supported by intersecting the value returned by the app’s supportedInterfaceOrientationsForWindow: method with the value returned by the supportedInterfaceOrientations method of the top-most full-screen controller. The setStatusBarOrientation:animated: method is not deprecated outright. It now works only if the supportedInterfaceOrientations method of the top-most full-screen view controller returns 0. This makes the caller responsible for ensuring that the status bar orientation is consistent.
For compatibility, view controllers that still implement the
shouldAutorotateToInterfaceOrientation:
method do not get the new autorotation behaviors. (In other words, they do not fall back to using the app, app delegate, or Info.plist file to determine the supported orientations.) Instead, theshouldAutorotateToInterfaceOrientation:
method is used to synthesize the information that would be returned by thesupportedInterfaceOrientations
method.
If you want your whole app to rotate then you should set your Info.plist to support all orientations. Now if you want a specific view to be portrait only you will have to do some sort of subclass and override the autorotation methods to return portrait only. Just have a look at How to force a UIViewController to Portrait orientation in iOS 6
Check your target properties...look like below
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return YES;
}