Force landscape mode in one ViewController using Swift

后端 未结 19 1251
情书的邮戳
情书的邮戳 2020-12-02 07:44

I am trying to force only one view in my application on landscape mode, I am calling

override func shouldAutorotate() -> Bool {
    print(\"shouldAutoro         


        
19条回答
  •  粉色の甜心
    2020-12-02 08:00

    Swift 4 , Tested in iOS 11

    You can specify the orientation in projectTarget -> General -> DeploymentInfo(Device Orientation) -> Portrait (Landscapeleft and Landscaperight are optional)

    AppDelegate

        var myOrientation: UIInterfaceOrientationMask = .portrait
        func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
            return myOrientation
        }
    

    LandScpaeViewController

    override func viewDidLoad() {
            super.viewDidLoad()
            let appDelegate = UIApplication.shared.delegate as! AppDelegate
            appDelegate.myOrientation = .landscape
    }
    

    OnDismissButtonTap

    let appDelegate = UIApplication.shared.delegate as! AppDelegate
     appDelegate.myOrientation = .portrait
    

    Thats it. :)

提交回复
热议问题