Force landscape mode in one ViewController using Swift

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

    Swift 4

    Trying to keep the orientation nothing worked but this for me:

    ...        
    override func viewDidLoad() {
           super.viewDidLoad()
           forcelandscapeRight()
           let notificationCenter = NotificationCenter.default
           notificationCenter.addObserver(self, selector: #selector(forcelandscapeRight), name: Notification.Name.UIDeviceOrientationDidChange, object: nil)
        }
    
        @objc func forcelandscapeRight() {
            let value = UIInterfaceOrientation.landscapeRight.rawValue
            UIDevice.current.setValue(value, forKey: "orientation")
        }
    ....
    
    0 讨论(0)
提交回复
热议问题