Sagit.Framework For IOS 开发框架入门教程16:屏幕旋转、屏幕强制旋转功能。

前言:

框架对屏蔽旋转作了很全面的封装处理,本篇来介绍一下使用屏幕旋转的相关功能。框架

屏幕旋转的相关方法定义:

#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;

下面介绍具体的使用:布局

一、【手动】设置屏幕【默认】的旋转

-(void)onInit
{
    [self rotateOrientation:UIInterfaceOrientationLandscapeRight];//设置旋转方向。

}

在初始化的地方,设置旋转,进入到该界面时,屏幕会自动旋转。atom

 

二、【容许】系统自动的屏幕旋转

-(void)onInit
{
    [self rotateOrientation:UIInterfaceOrientationLandscapeRight];//设置默认方向。

    self.onDeviceRotate = ^BOOL(NSNotification *notify,BOOL isEventRotate) {
        //返回true容许旋转布局、false不容许旋转布局。
        return true;
    };
}

设置onDeviceRote属性后,能够除了能够控制系统屏蔽旋转,连手工旋转的也能够拦截。spa

三、设置【容许】系统自动旋转的方向。

-(void)onInit
{
    [self rotateOrientation:UIInterfaceOrientationLandscapeRight];
    
[self setSupportedInterfaceOrientations:UIInterfaceOrientationMaskLandscape];

    self.onDeviceRotate = ^BOOL(NSNotification *notify,BOOL isEventRotate) {
        return true;
    };
}

PS:code

一、手工旋转的,不受支持的方向的约束。blog

二、设置支持的旋转方向,只能约束系统自动旋转手机产生的事件。 事件