Force rotation not working properly on iOS 15

The app has two methods to rotate globally the whole application:

  /// Changes the orientation to landscape right globally within the app.
  public static func landscapeRight() {
    if AppDelegate.orientationLock != .landscapeRight {
      AppDelegate.orientationLock = .landscapeRight
      UIDevice.current.setValue(UIInterfaceOrientation.landscapeRight.rawValue, forKey: "orientation")
      UINavigationController.attemptRotationToDeviceOrientation()
    }
  }
   
  /// Changes the orientation to portrait globally within the app.
  public static func portrait() {
    if AppDelegate.orientationLock != .portrait {
      AppDelegate.orientationLock = .portrait
      UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")
      UINavigationController.attemptRotationToDeviceOrientation()
    }
  }

So I was able to change the orientation for some screens (especially some that use the camera). But after iOS 15 update the rotation is not working properly anymore. Sometimes the app rotates but the screen seems to be divided into two parts and sometimes is not rotating at all.

Any ideas what could be the issue?

UIDevice.current.setValue(UIInterfaceOrientation.landscapeRight.rawValue, forKey: "orientation") is not accessing a public SDK-valid property of UIDevice. UIDevice only advertises a getter for the orientation property, not a setter, and code like this is attempting to get around that limitation and assume an implementation that may or may not exist (spoiler: it doesn't work like this and hasn't for a while).

The generally supported method to present a UI that requires a specific orientation is to use modal presentation to do so, while the view controller presented supports only the specifically supported orientations.

i have the same trouble.

On iPadOS15, UIDevice.current.setValue(UIInterfaceOrientation.landscapeRight.rawValue, forKey: "orientation") this method didn't work at all.

i want to force to rotate the UI at specific view.

Force rotation not working properly on iOS 15
 
 
Q