1. 前置設定
2. 手動螢幕翻轉
3. 恢復自動螢幕翻轉
1. 前置設定
在 AppDelegate.swift 內輸入以下程式碼,以下範例鎖定portrait
static var orientationLock = UIInterfaceOrientationMask.portrait func application( _ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow? ) -> UIInterfaceOrientationMask { return AppDelegate.orientationLock }
2. 手動螢幕翻轉
AppDelegate.orientationLock = UIInterfaceOrientationMask.landscapeLeft UIDevice.current.setValue( UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation" ) UIViewController.attemptRotationToDeviceOrientation()
3. 恢復自動螢幕翻轉
AppDelegate.orientationLock = UIInterfaceOrientationMask.all UIDevice.current.setValue( UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation" ) UIViewController.attemptRotationToDeviceOrientation()
訂閱Codeilin的旅程,若有最新消息會通知。
廣告
發表迴響