iPad Pro iPadOS 15.0.2 Orientation Changes Not working

975 views Asked by At

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

<key>UIRequiresFullScreen</key>
    <false/>
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationPortraitUpsideDown</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
2

There are 2 answers

1
Jayesh Patel On

Your can set the viewcontroller's presentationStyle as fullscreen to fix it..!!

2
mhtranbn On

You are good, this is a good question, thank you on behalf of many people.

I can explain specifically with your case as follows: The problem is: One of the differences between iPadOS and iOS is in the core of the iPadOS system developed by Apple support features like Slide Over and Split View that make it possible to use multiple different applications simultaneously, This means that the accepted way of managing windows uses multiple windows with the same main activity on the iPadOS screen.

UIViewController.attemptRotationToDeviceOrientation() still works but you are getting it wrong, it works on window with highest assignment layer (iOS conversely is not supported to ensure user design), this window is not container window your application home screens.

To fix your problem, you need to check if your project is using another window, that have lever higher(check: window.windowLevel)? you need to remove or set the property to hide windows with higher floors. For example: window.isHidden = true.

Cheers.