Force landscape mode in one ViewController using Swift

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

    In Xcode 11 with Swift 5 I Implemented the following. But it only works when the device orientation for the project target does not include all orientations. I disabled the check for Upside Down. After this, the following code works. If all checkboxes are enabled, the code is not called;

    class MyController : UINavigationController {
    
        override var shouldAutorotate: Bool {
            return true
        }
    
        override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
            return .landscape
        }
    
    
    }
    

提交回复
热议问题