Correctly fetch ViewController interfaceOrientation

44 Views Asked by At

I am using the following code to retrieve interface orientation of custom UIViewController (which is not a navigation/tabview controller).

   public var windowOrientation: UIInterfaceOrientation {
       return view.window?.windowScene?.interfaceOrientation ?? .unknown
   }

However, under some conditions, this code gives incorrect orientation while the deprecated -[UIViewController interfaceOrientation] gives correct results. Specifically, this happens when I have a custom logic to return supportedInterfaceOrientations on startup of the app where I wait for some events to happen before enabling autorotation. What is the correct way of retrieving interface orientation in that case.

0

There are 0 best solutions below