ios - 如何锁定显示为模态表单的 UIViewController 上的旋转?

标签 ios uiviewcontroller ios8 uikit ios9

我正在呈现一个 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/

相关文章:

ios - 双击 uitextview

iphone - 自定义登录 View 弹出窗口,如警报 View

ios - 如何设置@IBAction 来定位 UIView 子类

ios - ViewController 模态演示未出现

objective-c - applyBlurWithRadius 适用于 iPhone 6,而不是 6+ (UIImage+ImageEffects)

iphone - 私有(private)接口(interface)和多个实现

ios - 无法将类型 '([AnyObject]!, NSError!) -> Void' 的值转换为预期参数类型 'CLGeocodeCompletionHandler'

ios - viewDidAppear 调用了在 iOS8 中被关闭的 View Controller

swift - 如何在 swift 中为 SKShapeNode 设置动画?

swift - 如何在运行时预选表行?