我如何锁定作为模态表单表示的UIViewController的旋转?

时间:2016-04-04 15:41:32

标签: ios uiviewcontroller ios8 uikit ios9

我以模板形式呈现UIViewController呈现样式作为表单,当它显示为表单时,它不会锁定方向。表格模式演示样式在iPhone 6+横向显示时或iPad上任意旋转时看起来都不同。

我通过故事板segue呈现VC

此相同的代码在iPhone上的锁定方向(6+除外)中正常工作,但在样式为表单时不起作用。如何在iPad或iPhone 6 +上以纵向方式锁定模态表单?

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    return .Portrait
}

override func shouldAutorotate() -> Bool {
    return false
}

override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
    return .Portrait
}

1 个答案:

答案 0 :(得分:0)

此代码适用于我,希望它也适用于你

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
}