问题描述
我一直在处理iPadOS 13.1.3上与设备方向有关的UI故障.有任何解决方案或解决方法吗?
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?
说明
让我们让屏幕A模态显示屏幕B.屏幕A仅锁定为纵向,屏幕B支持所有方向.如果显示了屏幕A,则将设备旋转到横向,然后将要显示屏幕B,则屏幕A的尺寸首先会错误地调整大小,这将导致更严重的故障.
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.
图片
左图是在产生UI故障的iPad OS 13.1.3上拍摄的.右图是在安装了iOS 12.4.1且布局正确的iPad上记录的.所有附带的图像都是下面链接的github项目的一部分.
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.
项目
请随时使用此,对此问题进行详细了解存储库.
Please, feel free to have a closer look on the issue by using this repository.
谢谢.
在iPadOS 13.2上不再出现故障.
The glitch no longer occurs on iPadOS 13.2.
推荐答案
我像这样解决它:
-
删除您的
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?)
实现.让我们让视图控制器来处理这个问题.
Delete your implementation of
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?)
. Let's let the view controllers handle this.
在VC1中:
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
.portrait
}
还删除"hacky解决方案".
Also delete the "hacky solution".
在VC2中:
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
.all
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
.portrait
}
因此,我们得到的是VC2最初以纵向显示,但随后可以旋转.
So what we get is that VC2 appears initially in portrait but can then be rotated.
如果您希望VC2在出现后立即旋转为横向,请添加以下内容:
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()
}
这篇关于iPadOS 13上的屏幕旋转故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!