简体   繁体   English

如何在 Swift 中强制设备旋转?

[英]How to force device rotation in Swift?

I want to force a device rotation in Swift.我想在 Swift 中强制设备旋转。
I've read, that this code is supposed to work but it doesn't:我读过,这段代码应该可以工作,但没有:
let value = UIInterfaceOrientation.LandscapeRight.rawValue UIDevice.currentDevice().setValue(value, forKey: "orientation")

Is that maybe an old version or why isn't it working?那可能是旧版本还是为什么它不起作用?

The only supported way to force a device rotation is to do a fullscreen presented view controller whose supported orientations are limited to the one(s) you want.唯一支持的强制设备旋转的方法是做一个全屏呈现的视图控制器,其支持的方向仅限于你想要的方向。

Whatever other hacky stuff you may read on this topic (such as setting the device orientation in the code you gave) is wrong and unsupported.您可能会阅读有关此主题的任何其他 hacky 内容(例如在您提供的代码中设置设备方向)都是错误且不受支持的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM