Bao Tuan Diep Bao Tuan Diep - 2 months ago 8
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?


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