简体   繁体   中英

How to force device rotation in Swift?

I want to force a device rotation in 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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