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>
Your can set the viewcontroller's presentationStyle as fullscreen to fix it..!!