Force landscape mode in one ViewController using Swift

后端 未结 19 1252
情书的邮戳
情书的邮戳 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条回答
  •  Happy的楠姐
    2020-12-02 08:20

    Overwrite (in ViewController):

    override public var shouldAutorotate: Bool {
        return false
    } 
    
    override public var supportedInterfaceOrientations: UIInterfaceOrientationMask {
        return .landscapeRight
    }
    
    override public var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
        return .landscapeRight
    }
    

    Hint for ios 13. As of ios 13, VC has different modalPresentationStyle as .automatic and device present modal view instead of Full-Screen VC. To fix this one must set modalPresentationStyle to .fullScreen. Example:

    let viewController = YourViewController()
    viewController.modalPresentationStyle = .fullScreen
    

提交回复
热议问题