kivan cheng
kivan cheng

Reputation: 1

How to rotate screen with the `var shouldAutorotate` returns false

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

Answers (1)

Rajesh Loganathan
Rajesh Loganathan

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

Related Questions