Sagit.Framework For IOS 開發框架入門教程16:螢幕旋轉、螢幕強制旋轉功能。
阿新 • • 發佈:2020-09-14
前言:
框架對遮蔽旋轉做了很全面的封裝處理,本篇來介紹一下使用螢幕旋轉的相關功能。
螢幕旋轉的相關方法定義:
#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、設定支援的旋轉方向,只能約束系統自動旋轉手機產生的事件。