Search code examples
iosswiftuinavigationcontrollerviewcontroller

How to rotate orientation?


I want to rotate orientation when I switch from UINavigationController in portrait mode to UIViewController to landscape mode, but it doesn't work.

I tried

(UIApplication.shared.delegate as! AppDelegate).window!.rootViewController = playModeVc

but I can see the next viewController in portrait, but I want to see it in landscape mode. When I use

present(playModeVc, animated: true, completion: nil)

it doesn't deallocate memory.

I want to deallocate memory when I switch viewController. How can I do that?


Solution

  • What I understand from your question is that you want to force one view controller to always appear in landscape mode.

    Here is how to do it in Swift 3. Add this code to the view controller that you want to appear in landscape:

    override var supportedInterfaceOrientations: UIInterfaceOrientationMask {  
        return UIInterfaceOrientationMask.landscape  
    }  
    
    override var shouldAutorotate: Bool {  
        return false  
    }