0

I want to lock the device's orientation in a specific ViewController to only portrait but none of the available solutions are working. It is embedded in a UINavigationController.

I deployed it to iOS7 and in the general settings, both landscape and portrait are checked because I want it to rotate for other VCs other than the specific one.

extension UINavigationController {
public override func shouldAutorotate() -> Bool {

    return visibleViewController.shouldAutorotate()
}

public override func supportedInterfaceOrientations() -> Int {
    return visibleViewController.supportedInterfaceOrientations()
}
}

this portion of the code is in my ViewController class

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

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

2 Answers 2

1

"In iOS 8, all rotation-related methods are deprecated" (See documentation on UIViewController). This could be why it isn't working for you.

I am thinking that Apple has done this to keep the users' experience more consistent throughout the app.

Sign up to request clarification or add additional context in comments.

Comments

0

I figured out the problem which is since I am using SWRevealViewController, the parent VC overrides the subview's rotate settings.

Thus I just subclass it and adjust the autorotate and orientation settings as intended.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.