【发布时间】:2020-01-16 23:42:50
【问题描述】:
iOS 13/13.1 自动旋转的行为似乎与 iOS 12 不同。例如,我的应用允许用户在设置中将界面方向锁定为纵向或横向模式。
如果我在设备上设置了纵向旋转锁定并在 supportInterfaceOrientations 中返回 .landscape,则界面将保持纵向模式,直到我在设备上禁用纵向锁定方向。 iOS 12 似乎并非如此。事实上,在 iOS 13 中甚至都没有调用supportedInterfaceOrientations!
UIViewController.attemptRotationToDeviceOrientation() 在这种情况下也不起作用。
问题的根源是我在应用程序初始化时暂时将 shouldAutorotate 返回为 false,当一切都初始化时,我调用 UIViewController.attemptRotationToDeviceOrientation() 来触发自动旋转。它在 iOS 12 中触发自动旋转,但在 iOS 13.1 中它不起作用。
看起来可能是 iOS 13.1 中的一个错误。如何强制触发自动旋转?
编辑:看起来 iOS 12.4.1 也忽略了 UIViewController.attemptRotationToDeviceOrientation()。 iOS 12.4.1 及更高版本的自动旋转出现问题。
说清楚,这就是我想要的:
一个。即使在 iPhone 上设置了纵向锁定,我希望我的界面在需要时自动旋转到横向模式,
b. UIViewController.attemptRotationToDeviceOrientation() 在所有情况下触发自动旋转的替代方案。
【问题讨论】:
-
supportedInterfaceOrientations 如果显示视图控制器将不会被调用。它会在全屏呈现时调用,但默认情况下,iOS 13 的 UIModalpresentationStyle 不是全屏的。
标签: ios swift uiviewcontroller autolayout autorotate