mafioso
mafioso

Reputation: 1632

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?

Upvotes: 1

Views: 791

Answers (1)

matt
matt

Reputation: 535202

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.

Upvotes: 3

Related Questions