iOS 13/13.1 Bug with Autorotation

iOS 13/13.1 autorotation seems to be behave differently than iOS 12. For instance, my app allows user to lock interface orientation to portrait or landscape mode in settings.

  1. If I have portrait rotation lock on device and return only .landscape mode as supportedInterfaceOrientations, the interface remains in portrait mode only until I disable portrait lock orientation on device. This does not seem to be the case with iOS 12. Infact, supportedInterfaceOrientations is not even called!
  2. UIViewController.attemptRotationToDeviceOrientation() also does not work in such cases.

The root of the problem is I temporarily return shouldAutorotate to false while the app is initializing and when everything is initialized, I call UIViewController.attemptRotationToDeviceOrientation() to trigger autorotation. It triggers autorotation in iOS 12 but in iOS 13.1 it doesn't works.

Looks like a bug in iOS 13.1 I believe. What's a known workaround?

Replies

I've encountered same problem. Were you able to find any workaround?

Only Apple Engineers can help.

I've got a similar issue. I'm trying to push a portrait view over a landscape view and this used to work, now it's broken in iOS 13.


Here's a simple example: https://github.com/dpreuitt/testPortrait.git.


I don't know what to do.

Your can set the portraitViewController's modalPresentationStyle as fullscreen

Setting viewcontroller's presentationStyle to fullscreen worked for me.

Awesome. That did the trick

Thank you very much ! This did help me.

Thank you very much! This helped me!

Dear UIKit Engineers,

Do you have any inputs on this, still looks unresolved on iOS14!
The only unofficial solution to forcefully rotate the device is by using this code, but it is undocumented. Can't use it in production code as one day it may be broken.

Code Block
 if view.bounds.width > view.bounds.height {
            UIDevice.current.setValue(UIDeviceOrientation.portrait.rawValue, forKey: "orientation")
        } else {
            UIDevice.current.setValue(UIDeviceOrientation.landscapeLeft.rawValue, forKey: "orientation")
        }


This works no matter whether the portrait orientation is locked on device or not.
There is another solution I found. Present & dismiss a custom dummy view controller which should be full screen and whose supportedInterfaceOrientations are precisely the orientation you want your view controller to be set to. This does not use unofficial APIs but is a hack to force autorotation.
Go to the project settings General > Deployment Info and make sure you have checked "Requires full screen" setting.