Oleg
Oleg

Reputation: 1097

One controller in landscape orientation

I have an app, which consists of one Tab bar controller which contains 4 navigation controllers. I can't find any solution to have one controller in the hierarchy of the navigation controllers to be only in landscape mode. All other controllers suppose to be portrait. Appreciate any help on this issue.

Upvotes: 0

Views: 46

Answers (2)

Andres Carmona
Andres Carmona

Reputation: 3

so i tried the following solution and it worked for me:

In AppDelegate.swift:

var currViewController: UIViewController?

func application(application: UIApplication, supportedInterfaceOrientationForWindows window: UIWindow?) -> UIInterfaceOrientationMask {
  if currViewController is MyCustomController {
    return UIInterfaceOrientationMask.LandscapeLeft
  } else {
    return UIInterfaceOrientationMask.Portrait
  }
}

In MyCustomController.swift:

let oAppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate

override func viewDidLoad(){
  super.viewDidLoad()
  oAppDelegate.currViewController = self
}

Upvotes: 0

William Anderson
William Anderson

Reputation: 287

In the viewDidLoad(): of the navigation controller that you want to be landscape, include:

let value = UIInterfaceOrientation.LandscapeLeft.rawValue
UIDevice.currentDevice().setValue(value, forKey: "orientation")

be sure to add the following override too

override func shouldAutorotate() -> Bool {
    return true
}

Upvotes: 2

Related Questions