I have an UIViewController, I want to disable or enable rotation of the screen in different scenarios
Example:
if flag {
rotateDevice = false
}
e
You simply have to implement shouldAutorotate
and supportedInterfaceOrientations
into your UIViewController
. Take a look at this documentation. For example:
override func shouldAutorotate() -> Bool {
return true
}
You can also specify which orientations are available. Here is an example with only portraits orientations:
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return .Landscape
}
Edit: If you want to support different orientation regarding a flag, you just have to do something like this:
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
if myFlag {
return .Landscape
} else {
return .All
}
}
(If myFlag
is true, it will allow Landscape
orientation. Otherwise, it will allow all orientations).
set device orientarion portrait in Target -> General -> Deployment Info -> Portrait