我想以横向模式呈现UIView
控制器,并禁用此UIViewController
的任何其他旋转。我尝试了以下操作,但用户仍然可以旋转出风景。
override func viewDidLoad() {
super.viewDidLoad()
applyLandscapeAndLock()
build()
// Do any additional setup after loading the view.
}
override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
return UIInterfaceOrientation.LandscapeLeft
}
override func shouldAutorotate() -> Bool {
return false
}
override func supportedInterfaceOrientations() -> Int {
return UIInterfaceOrientation.LandscapeLeft.rawValue
}
func applyLandscapeAndLock() {
let value = UIInterfaceOrientation.LandscapeLeft.rawValue
UIDevice.currentDevice().setValue(value, forKey: "orientation")
}