Bao Tuan Diep Bao Tuan Diep - 1 year ago 143
Swift Question

iOS. How can enable or disable rotate on one UIViewController

I have one UIViewController, I want to rotate or not rotate the screen in different cases


if flag {
rotateDevice = false
else {
rotateDevice = true

How can I do that?

Answer Source

I have the answer. On AppDelegate, if you rotate device, push viewcontroller,... This function alway call

func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask
    if self.restrictRotation {
        return UIInterfaceOrientationMask.All
    else {
        return UIInterfaceOrientationMask.Landscape

Make restrictRotation type is static and change it if you want to your custom orientation device

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download