写了一篇关于屏幕强制旋转的文章,可是有人跟我反应说没成功,状态栏依旧没有改变。原因是他的rootViewController是UINavigationController跟UITabBarController混合使用的。
因为UINavigationController跟UITabBarController也是UIViewController,所以会覆盖其子页面的旋转方法。
解决方法:添加以下类
//
// UINavigationController+Rotation_IOS6.m
// djy
//
// Created by SuFuTe on 14/12/30.
// Copyright (c) 2014年 SuFuTe. All rights reserved.
//
#import "UINavigationController+Rotation_IOS6.h"
@implementation UINavigationController (Rotation_IOS6)
-(BOOL)shouldAutorotate {
NSLog(@"UINavigationController 100");
// 不想其子页面支持旋转, 可直接返回 NO
return YES;
}
-(NSUInteger)supportedInterfaceOrientations {
NSLog(@"UINavigationController 200");
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
NSLog(@"UINavigationController 300");
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
@end
//
// UITabBarController+Rotation_IOS6.m
// djy
//
// Created by SuFuTe on 14/12/30.
// Copyright (c) 2014年 SuFuTe. All rights reserved.
//
#import "UITabBarController+Rotation_IOS6.h"
@implementation UITabBarController (Rotation_IOS6)
-(BOOL)shouldAutorotate {
NSLog(@"UITabBarController 100");
// 不想其子页面支持旋转,可直接返回 NO
return YES;
}
-(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
AppDelegate.m中导入头文件
#import "UINavigationController+Rotation_IOS6.h"
#import "UITabBarController+Rotation_IOS6.h"
-(BOOL)shouldAutorotate;
-(NSUInteger)supportedInterfaceOrientations;
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;