Wraithseeker
Wraithseeker

Reputation: 1904

iOS lock specific ViewController to specific orientation

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)
}

Upvotes: 0

Views: 206

Answers (2)

Wraithseeker
Wraithseeker

Reputation: 1904

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.

Upvotes: 0

Jeff Lewis
Jeff Lewis

Reputation: 2866

"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.

Upvotes: 1

Related Questions