Force landscape mode in one ViewController using Swift

后端 未结 19 1249
情书的邮戳
情书的邮戳 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:11

    // below code put in view controller
    // you can change landscapeLeft or portrait
    
    override func viewWillAppear(_ animated: Bool) {
            UIDevice.current.setValue(UIInterfaceOrientation.landscapeRight.rawValue, forKey: "orientation")
        }
    
    override var shouldAutorotate: Bool {
            return true
        }
        override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
            return .landscapeRight
        }
        override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
            return .landscapeRight
        }
    

提交回复
热议问题