patrikbelis
patrikbelis

Reputation: 1360

Turn off rotation?

trying to turn off that user can't change orientation..

I have my view in landscape and it must be in landscaped so I'm doing it this way

    let value = UIInterfaceOrientation.landscapeLeft.rawValue
    UIDevice.current.setValue(value, forKey: "orientation")

And also with this that user can't change rotation

    private func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
         return UIInterfaceOrientationMask.landscapeLeft
    }
    private func shouldAutorotate() -> Bool {
        return false
    }

The problem is that it isn' t working. I have after pushing landscaped but I'm still can rotate it.

Upvotes: 1

Views: 68

Answers (1)

Nirav D
Nirav D

Reputation: 72410

From swift 3 shouldAutorotate and supportedInterfaceOrientations is property not method, so you need to add it like this.

override var shouldAutorotate: Bool {
     return false
}

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
     return UIInterfaceOrientationMask.landscapeLeft
}

Upvotes: 3

Related Questions