问题
I've been dealing with a UI glitch on iPadOS 13.1.3 that is related to device orientation. Is there any solution or workaround for this?
Issue
Description
Let's have screen A that displays modally screen B. Screen A is locked to portrait only and screen B supports all orientations. If screen A is displayed, device is rotated to landscape then and screen B is about to be displayed, screen A is resized incorrectly first which results a wierd glitch.
Images
The left images is taken on iPadOS 13.1.3 that produces the UI glitch. Image on the right is recorded on iPad with iOS 12.4.1 installed where the layout is correct. All the attached images are part of the github project linked below.
Project
Please, feel free to have a closer look on the issue by using this repository.
Thanks.
Edit:
The glitch no longer occurs on iPadOS 13.2.
回答1:
I worked around it like this:
Delete your implementation of
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?)
. Let's let the view controllers handle this.In VC1:
override var supportedInterfaceOrientations: UIInterfaceOrientationMask { .portrait }
Also delete the "hacky solution".
In VC2:
override var supportedInterfaceOrientations: UIInterfaceOrientationMask { .all } override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation { .portrait }
So what we get is that VC2 appears initially in portrait but can then be rotated.
If you want VC2 to rotate immediately into landscape after appearing, then add this:
var appeared = false
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
appeared = true
UIViewController.attemptRotationToDeviceOrientation()
}
来源:https://stackoverflow.com/questions/58521687/screen-rotation-glitch-on-ipados-13