0
votes

How can I force change orientation, when viewWillAppear?

I want only one navigationController to force landscape, other controllers I want to portrait.

When I push to landscape controller it shows like portrait, but when I rotate mobile, it locks, like landscape like I want.

How can I do that, when vieWillAppear? Is there any function to that?

1

1 Answers

1
votes
override func viewDidLoad() {
    super.viewDidLoad()
    let value = UIInterfaceOrientation.landscape.rawValue
    UIDevice.current.setValue(value, forKey: "orientation")
}

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    return .landscape
}

override var shouldAutorotate: Bool {
    return true
}