iPad Pro iPadOS 15.0.2 Orientation Changes Not working

My application is support for iPhone and scale with iPad(not support full screen on iPad).

We are programmatically changing the orientation to landscape whenever this function is working fine on iphone(all of ios versions) . But screen rotation functionality is not working on iPad Pro iPadOS 15.0 and above.

I debug it, the rotation state is set to the "orientation" key, but UIViewController.attemptRotationToDeviceOrientation() function doesn't seem to be reflecting the state to the application.

Below is the code to perform screen rotation. Could you please help check it?

Enviroment:
Xcode: 12.2(12B45b), Version 13.0 (13A233) 
Simulator: iPad Pro(12.9-inch) OS15.0
Device: iPad Pro 11inch (gen2) OS 15.0.2

Appdelegate:

    func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
        return ScreenOrientationManager.shared.currentOrientation
    }

RotationManager class:


class ScreenOrientationManager: NSObject {
        static let shared: ScreenOrientationManager = ScreenOrientationManager()
	var currentOrientation: UIInterfaceOrientationMask = .portrait 

@discardableResult
func rotateScreen() {
        if self.currentOrientation == .portrait {
           self.currentOrientation = .landscape
	   UIDevice.current.setValue(UIInterfaceOrientation.landscapeRight.rawValue, forKey: "orientation")
        } else {
           self.currentOrientation = .portrait
	   UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")
        }
        UIViewController.attemptRotationToDeviceOrientation() // *→ Not working on iPadOS15*
}

Project setting

Did you notice in doc for enum UIInterfaceOrientation:

Starting in iOS 8, you should employ the UITraitCollection and UITraitEnvironmentAPIs, and size class properties as used in those APIs, instead of using UIInterfaceOrientation constants or otherwise writing your app in terms of interface orientation.

You may have to set keys in info.plist ?

I have checked and edited the plist file, but the result has not changed.

Result is the application in horizontal state on the ipad, but rotate button is clicked, the rotation event still doesn't work. (happens with ipad only, on iphone is works fine.)

Could you show 2 screens on iPad, before and after rotation ?

Please, reduce the size on the screen capture (in Preview) by a factor of 3 at least, to avoid huge image in the forum).

Note: why not support iPad deployment ?

I tested in simulator (iPad OS 15) your code on an app that I restricted to iPhone only:

I have created a button :

    @IBAction func testAlert(_ sender: Any) {
         ScreenOrientationManager.shared.rotateScreen()
    }

Note :     @discardableResult is not needed

before rotation:

After rotation by tapping button (device does not rotate of course in simulator, but content does).

We see the content as rotated, as required for iPhone

If I rotate iPad, I get the correct display.

Is it what you expect ?

@Claude31:

Note: why not support iPad deployment ?

Reason that we can't prepare the specific design for the ipad, we can only scale it from iPhone's design.

I tried with a new project with the above settings, but it still can't rotate the screen. when clicking on the event of the button absolutely nothing happens.

Rotate Button's action

   @IBAction func rotation(_ sender: Any) {
    ScreenOrientationManager.shared.rotateScreen()
  }

A difference: I have not the key Requires full screen in info.plist.

Have you defined constraints ?

If that's a small project, could you send it ? Post temporarily an email address here to send a zip of the complete project folder.

iPad Pro iPadOS 15.0.2 Orientation Changes Not working
 
 
Q