Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autorotation bug in iOS 13

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 .landscape in supportedInterfaceOrientations, the interface remains in portrait mode 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 in iOS 13!

  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 probably. What do I do to force trigger autorotation?

EDIT: Looks like iOS 12.4.1 also ignores UIViewController.attemptRotationToDeviceOrientation(). There is something broken in autorotation in iOS 12.4.1 & above.

To be clear, this is what I want:

a. Even if portrait lock is set on iPhone, I wish my interface to autorotate to landscape mode if required,

b. UIViewController.attemptRotationToDeviceOrientation() alternative that triggers autorotation in all circumstances.

like image 345
Deepak Sharma Avatar asked Sep 16 '19 06:09

Deepak Sharma


People also ask

How do I fix the screen rotation on my iPhone 13?

Swipe down from the top-right corner of your screen to open Control Center. Tap the Portrait Orientation Lock button to make sure that it's off.

Why do my apps keep rotating?

If you've enabled auto-rotate, your Android phone's screen is supposed to rotate when turn your phone 90 degrees or more. Sometimes, though, you might notice that this doesn't happen. It's possible a third-party app, a system glitch, or a faulty sensor is causing your phone not to recognize the movement.

How do I stop auto rotate on my iPhone?

Swipe down from the top right-hand corner of your screen to open Control Centre. Tap the Portrait Orientation Lock button to make sure it's turned off.


1 Answers

From iOS 12.4.1, View Controller should be set to Full Screen to respect the auto-rotate orientation.

let vc = UIViewController()
vc.modalPresentationStyle = .fullScreen
self.present(vc, animated: true, completion: nil)
like image 146
Teja Konjeti Avatar answered Sep 18 '22 07:09

Teja Konjeti