1、描述
self.window.rootViewController = UINavigationController 或 UITabBarController。
或者是混合使用的,如: UINavigationController 下包含UITabBarController
因 UINavigationController、UITabBarController 也是 UIViewController,所以会覆盖其子页面的旋转方法
2、解决,添加类
@interface UINavigationController (Rotation_IOS6) -(BOOL)shouldAutorotate; -(NSUInteger)supportedInterfaceOrientations; -(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation; @end #import "UINavigationController+Rotation_IOS6.h" @implementation UINavigationController (Rotation_IOS6) -(BOOL)shouldAutorotate { NSLog(@"UINavigationController 100"); // 不想其子页面支持旋转, 可直接返回 NO return [[self.viewControllers lastObject] shouldAutorotate]; } -(NSUInteger)supportedInterfaceOrientations { NSLog(@"UINavigationController 200"); return [[self.viewControllers lastObject] supportedInterfaceOrientations]; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { NSLog(@"UINavigationController 300"); return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation]; } @end
@interface UITabBarController (Rotation_IOS6) -(BOOL)shouldAutorotate; -(NSUInteger)supportedInterfaceOrientations; -(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation; @end @implementation UITabBarController (Rotation_IOS6) -(BOOL)shouldAutorotate { NSLog(@"UITabBarController 100"); // 不想其子页面支持旋转,可直接返回 NO return [[self.viewControllers lastObject] shouldAutorotate]; } -(NSUInteger)supportedInterfaceOrientations { NSLog(@"UITabBarController 200"); //return UIInterfaceOrientationMaskPortrait; return [[self.viewControllers lastObject] supportedInterfaceOrientations]; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { NSLog(@"UITabBarController 300"); //return UIInterfaceOrientationPortrait; return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation]; }@end
#import "UINavigationController+Rotation_IOS6.h" #import "UITabBarController+Rotation_IOS6.h"
- (BOOL)shouldAutorotate { - (NSUInteger)supportedInterfaceOrientations{ - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
5、ios5 支持屏幕旋转
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait); }