iOS 6 对设备转向时 View Rotations 的处理完全不一样了
Handling View Rotations
In iOS 6, your app supports the interface orientations defined in your app’s Info.plist
file. A view controller can override thesupportedInterfaceOrientations
method to limit the list of supported orientations. Generally, the system calls this method only on the root view controller of the window or a view controller presented to fill the entire screen; child view controllers use the portion of the window provided for them by their parent view controller and no longer participate in directly in decisions about what rotations are supported. The intersection of the app’s orientation mask and the view controller’s orientation mask is used to determine which orientations a view controller can be rotated into.
You can override the preferredInterfaceOrientationForPresentation
for a view controller that is intended to be presented full screen in a specific orientation.
In iOS 5 and earlier, the UIViewController
class displays views in portrait mode only. To support additional orientations, you must override the shouldAutorotateToInterfaceOrientation:
method and return YES
for any orientations your subclass supports. If the autoresizing properties of your views are configured correctly, that may be all you have to do. However, the UIViewController
class provides additional hooks for you to implement additional behaviors as needed. Generally, if your view controller is intended to be used as a child view controller, it should support all interface orientations.
When a rotation occurs for a visible view controller, the willRotateToInterfaceOrientation:duration:
,willAnimateRotationToInterfaceOrientation:duration:
, and didRotateFromInterfaceOrientation:
methods are called during the rotation. The viewWillLayoutSubviews
method is also called after the view is resized and positioned by its parent. If a view controller is not visible when an orientation change occurs, then the rotation methods are never called. However, theviewWillLayoutSubviews
method is called when the view becomes visible. Your implementation of this method can call thestatusBarOrientation
method to determine the device orientation.
Note: At launch time, apps should always set up their interface in a portrait orientation. After theapplication:didFinishLaunchingWithOptions:
method returns, the app uses the view controller rotation mechanism described above to rotate the views to the appropriate orientation prior to showing the window.
但假如你最上层的viewcontroller 是个tabviewcontroller又不一样了 你必须
@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
参见: http://stackoverflow.com/questions/12410031/the-new-ios-rotations-supportedinterfaceorientations-doesnt-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