ios - UIDevice.current.setValue(value, forKey : "orientation") does not work if phone held in landscape and tilted 45 - 90 degrees

标签 ios swift orientation

我在用

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/

相关文章:

android - 如何在方向更改时保留 EditText 数据?

ios - 自动旋转模态视图

ios - 如何在没有子类 UITableViewCell 的情况下设置 UITableViewCell 的 AccessoryView 的框架

ios - 如何在iOS中获取具体日期?

c# - 视觉树中的WP7弹出窗口不尊重方向

ios - UIScrollView 中缩放图像数组

ios - 无法在 Swift 中扩展 Objective-C 类

android - 检测移动设备的屏幕键盘中的键是否可用

ios - 有没有办法在解析服务器上安排推送通知?

ios - http 流视频 PlaybackDidFinish 未调用