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;

下面介紹具體的使用:

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、設置支持的旋轉方向,只能約束系統自動旋轉手機產生的事件。 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM