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

二、設置支持的旋轉方向,只能約束系統自動旋轉手機產生的事件。 事件