我在用
let value = UIInterfaceOrientation.landscapeRight.rawValue
UIDevice.current.setValue(value, forKey: "orientation")
强制呈现 View Controller 以横向显示。这是导航 Controller 流程的一部分。这按预期工作,但如果手机横向放置并倾斜 45 到 90 度, View 将以纵向显示。该方法被调用并且预期值是正确的,但景观没有发生变化。这可以在带有导航 Controller 的基本项目中重现。
有谁知道是什么导致了这种行为?
最佳答案
我也遇到了这个奇怪的问题,当您将设备旋转到您想要在进入下一个 View Controller 时更改的方向时,屏幕会保持纵向模式。我设法通过调用解决了这个问题
UINavigationController.attemptRotationToDeviceOrientation()
之后
UIDevice.current.setValue(value, forKey: "orientation")
被调用了。
我想这只有在您使用 UINavigationController
时才有效。
关于ios - UIDevice.current.setValue(value, forKey : "orientation") does not work if phone held in landscape and tilted 45 - 90 degrees,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44209577/