ios 屏幕旋转的问题

在ios6之前我们旋转屏幕只需要实现shouldAutorotateToInterfaceOrientation就行了

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}
但是ios6上这个就失效了,需要实现shouldAutorotate 和 supportedInterfaceOrientations
具体步骤是
1. Delegate里面要分开判断ios版本,setRootViewController方法是不同的:
1 if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0){
2         // warning: addSubView doesn't work on iOS6
3         [self.window addSubview: navController.view];
4 }
5 else{
6         // use this mehod on ios6
7         [self.window setRootViewController:navController];
8 }
2. 因为我们要向下兼容, 所以shouldAutorotateToInterfaceOrientation必须保留, 再添加shouldAutorotate 和 supportedInterfaceOrientations
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}
- (BOOL)shouldAutorotate {
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}
这样应该没问题了, 但是需要注意的有两点:
1. 必须在.plist文件中添加你需要旋转的方向,要对应, 不然还是没效果
2. 我这里的rootView是UINavigationController, 所以要子类化并添加上面的两个方法, 但是我是添加了Category来实现的
UINavigationController + Rotation.h
@interface UINavigationController (Rotation)
@end
UINavigationController + Rotation.m
@implementation UINavigationController (Rotation)
- (BOOL)shouldAutorotate {
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}
@end
原文地址:https://www.cnblogs.com/lihaibo-Leao/p/3284434.html