我正在呈现一个 UIViewController
模态,呈现样式为 Form Sheet,当它显示为 Form Sheet 时它没有锁定方向。在 iPhone 6+ 横向显示或在 iPad 上以任意旋转显示时,表单模式呈现样式看起来不同。
我正在通过 Storyboard转场展示 VC
此相同的代码在 iPhone(6+ 除外)的锁定方向上正常工作,但在样式为表单时不起作用。如何在 iPad 或 iPhone 6+ 上以纵向锁定模态表单?
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return .Portrait
}
override func shouldAutorotate() -> Bool {
return false
}
override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
return .Portrait
}
最佳答案
这段代码对我有用,希望对你也有用
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let val = UIInterfaceOrientation.Portrait;
UIDevice .currentDevice() .setValue(val, forKey: "orientation");
}
override func shouldAutorotateToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation) -> Bool {
return (toInterfaceOrientation == UIInterfaceOrientation.Portrait)
}
override func shouldAutorotate() -> Bool {
return false
}
关于ios - 如何锁定显示为模态表单的 UIViewController 上的旋转?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36407112/