2

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 Answers2

0

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

Jayesh Patel
  • 938
  • 5
  • 16
  • Is there any other way? beacause i using rotation on once view(using Autolayout constraints).Rotate function called works fine on iphone but not work on ipad. it's weird. Thank you for your comment. – LAI THE ANH Oct 15 '21 at 04:58
0

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.

mhtranbn
  • 1
  • 1
  • 3
  • I tried creating a new project, with the same test code as above. I sure only 1 windows are in using. With that project screen rotation works fine on iphone(all of version) but it's not working on iPadOS 15.0 and above. If you have another way and share it with me, I will be very happy. Thank you for your comment. – LAI THE ANH Oct 18 '21 at 04:51
  • Could you upload your example on git? I can help you, you can, and you can continue to help many others. – mhtranbn Oct 19 '21 at 14:17