前言:
框架對屏蔽旋轉做了很全面的封裝處理,本篇來介紹一下使用螢屏旋轉的相關功能,
螢屏旋轉的相關方法定義:
#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、設定支持的旋轉方向,只能約束系統自動旋轉手機產生的事件,
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/106815.html
標籤:其他
上一篇:移動端技術選型
