前言:
框架对屏蔽旋转做了很全面的封装处理,本篇来介绍一下使用屏幕旋转的相关功能。
屏幕旋转的相关方法定义:
- #pragma mark 屏幕旋转
- //!屏幕旋转事件:【 return true 系统调用刷新布局([self.view refleshLayoutAfterRotate];);return false 用户自己手动控制】 @isEventRotate 是旋转屏幕、还是点击事件触发。
- typedef BOOL(^OnRotate)(NSNotification* notify,BOOL isEventRotate);
- //!屏幕旋转事件。
- @property (nonatomic,assign) OnRotate onDeviceRotate;
- //!设置当前视图支持的屏幕旋转方向
- -(void)setSupportedInterfaceOrientations:(UIInterfaceOrientationMask)orientation;//!手动调用旋转屏幕。
- -(STController*)rotateOrientation:(UIInterfaceOrientation)direction;
下面介绍具体的使用:
1、【手动】设置屏幕【默认】的旋转
- -(void)onInit
- {
- [self rotateOrientation:UIInterfaceOrientationLandscapeRight];//设置旋转方向。
- }
在初始化的地方,设置旋转,进入到该界面时,屏幕会自动旋转。

2、【允许】系统自动的屏幕旋转
- -(void)onInit
- {
- [self rotateOrientation:UIInterfaceOrientationLandscapeRight];//设置默认方向。
- self.onDeviceRotate = ^BOOL(NSNotification *notify,BOOL isEventRotate) {
- //返回true允许旋转布局、false不允许旋转布局。
- return true;
- };
- }
设置onDeviceRote属性后,可以除了可以控制系统屏蔽旋转,连手工旋转的也可以拦截。

3、设置【允许】系统自动旋转的方向。
- -(void)onInit
- {
- [self rotateOrientation:UIInterfaceOrientationLandscapeRight];
-
- [self setSupportedInterfaceOrientations:UIInterfaceOrientationMaskLandscape];
- self.onDeviceRotate = ^BOOL(NSNotification *notify,BOOL isEventRotate) {
- return true;
- };
- }
PS:
1、手工旋转的,不受支持的方向的约束。
2、设置支持的旋转方向,只能约束系统自动旋转手机产生的事件。