iOS 6.0以上版本的旋屏控制处理

我们都知道,在iOS 6.0以下,支持旋屏的函数如下:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

我们只要对不同的interfaceOrientation返回YES或NO即可支持对应的屏幕旋转。在6.0以后,旋转函数改为:

- (NSUInteger)supportedInterfaceOrientations

需要自己返回对应的orientations。

但是在实践中发现,当个controller的supportedInterfaceOrientations根本没有调用。经过查看资料分析,原来在6.0以上,旋屏的控制放在了navgationController,所以我们需要自定义一个navgationController,定义相关的变量来处理是否支持旋转。

//写子类NavigationController的目的是因为6.0以上,把旋屏的控制放在了UINavigationController

 @interface LRNavigationController : UINavigationController

 //是否支持旋屏幕

@property(nonatomic,assign)BOOL shouldRotate;

 @end

实现如下:

@implementation LRNavigationController

 @synthesize shouldRotate = _shouldRotate;

#pragma  mark roate method

- (BOOL)shouldAutorotate

{

    return_shouldRotate;

}

 - (NSUInteger)supportedInterfaceOrientations{

    return_shouldRotate ? UIInterfaceOrientationMaskAllButUpsideDown : UIInterfaceOrientationMaskPortrait;

}

这样在6.0以上,就可以通过获取navgationController更改_shouldRotate的值,实现旋转的控制。

 

 

原文地址:https://www.cnblogs.com/vicstudio/p/3102621.html