-1

I have encountered problem when presenting view controller and changing its orientation to landscape at the same time. It's just working fine with devices in iOS 12 and below. It's also working fine with iPhones in iOS 13.

   override func viewWillAppear(_ animated: Bool) {
        self.addObserver()
        let value = UIInterfaceOrientation.landscapeRight.rawValue
        UIDevice.current.setValue(value, forKey: "orientation")
   }

    override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
        return .landscapeRight
    }

    override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
        return .landscapeRight
    }
rmaddy
  • 314,917
  • 42
  • 532
  • 579
ylj_
  • 11
  • 3
    `UIDevice.current.setValue(value, forKey: "orientation")` has never been supported code. Don't use `setValue(_:forKey:)` to change private APIs. – rmaddy Sep 18 '19 at 05:43

1 Answers1

-1

use this

override func viewWillAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    if #available(iOS 13.0, *) {
    self.addObserver()
    let value = UIInterfaceOrientation.landscapeRight.rawValue
    UIDevice.current.setValue(value, forKey: "orientation")
    }
}

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    return .landscapeRight
}

override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
    return .landscapeRight
}
Masoud Roosta
  • 455
  • 9
  • 19