2

I want the general orientation of my app to be portrait, but for one specific UIViewController (VC2B) I want the user to be able to tilt the device for landscape orientation. (VC2B has a navigation bar)

I have tried different types of code but without luck. Ideally I would like to to enable rotation in only UIViewController (VC2B). But this seems impossible, instead it seems you have to enable all the orientations in the General section and then turn them off programatically - is this really true?

Anyway I have tried various things

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

override func supportedInterfaceOrientations() -> Int {
    return Int(UIInterfaceOrientation.LandscapeLeft.rawValue) | Int(UIInterfaceOrientation.LandscapeRight.rawValue) | Int(UIInterfaceOrientation.Portrait.rawValue)
}

The below answer suggest overriding shouldAutorotate to false, but that does not work if the page is loaded in landscape mode, then it is just stuck on landscape.

Allow all orientations for only one view controller

Question: How can I in a tidy way, without adding code to all my UIViewControllers, allow multiple orientations for only one UIViewController?

Community
  • 1
  • 1
KML
  • 2,302
  • 5
  • 26
  • 47
  • How are you showing that specific viewcontroller? as Modal? or Pushing into NavigationController? – iphonic May 13 '15 at 08:43
  • NC ------> VC1B ---push---> VC2B – KML May 13 '15 at 08:46
  • possible duplicate of [How to lock device orientation in iOS 7 and iOS 8](http://stackoverflow.com/questions/29962727/how-to-lock-device-orientation-in-ios-7-and-ios-8) – David Ansermot May 13 '15 at 08:51
  • You can create a BaseViewController, add Portrait rotation to that, assign that to all of your ViewController, and implement all rotation separately for that viewcontroller(*VC2B*) – iphonic May 13 '15 at 08:57

1 Answers1

0

Do the following as I did this when I faced same situation:

enable the desired orientations in the General Info Screen in each ViewController.swift, override the autorotation function with either true or false (true for the one that should rotate, false for the others)

iAnurag
  • 9,286
  • 3
  • 31
  • 48
  • That only works if all the VC's are loaded push, fails if loaded modal. The View will then load in whatever orientation the phone has at the time. – KML May 13 '15 at 09:11