Reputation: 1
How to set the specified page rotation without having it rotate automatically? I found that the screen can rotate only when var shouldAutorotate
returns yes, but I don't want to do that automatically,I want to control the moment of rotate by myself
Upvotes: 0
Views: 134
Reputation: 11247
Swift 4+:
Use following code to rotate screen when required without any auto rotation as you want.
func rotateToLandscapeRight() {
UIDevice.current.setValue(UIInterfaceOrientation.landscapeRight.rawValue, forKey: "orientation")
}
func rotateToLandscapeLeft() {
UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation")
}
func rotateToPortratit() {
UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")
}
Upvotes: 0