【问题标题】:Setting UIModalPresentationStyle for iPhone 6 Plus in landscape?为 iPhone 6 Plus 横向设置 UIModalPresentationStyle?
【发布时间】:2015-04-26 22:37:00
【问题描述】:

我希望始终在所有设备和所有方向上的弹出窗口中显示视图控制器。我试图通过采用UIPopoverPresentationControllerDelegate 并设置sourceViewsourceRect 来实现这一点。故事板中的 segue 被配置为 Present As Popover segue。这适用于所有设备和方向,除了 iPhone 6 Plus 横向。在这种情况下,视图控制器会在表单中从屏幕底部向上滑动。我怎样才能防止它总是出现在弹出窗口中?

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    let popoverPresentationController = segue.destinationViewController.popoverPresentationController
    popoverPresentationController?.delegate = self
    popoverPresentationController?.sourceView = self.titleLabel!.superview
    popoverPresentationController?.sourceRect = self.titleLabel!.frame
}

func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
    return UIModalPresentationStyle.None
}

【问题讨论】:

    标签: ios uipresentationcontroller


    【解决方案1】:

    实现UIAdaptivePresentationControllerDelegate 的新(从iOS 8.3 开始)adaptivePresentationStyleForPresentationController:traitCollection: 方法:

    - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller traitCollection:(UITraitCollection *)traitCollection {
        // This method is called in iOS 8.3 or later regardless of trait collection, in which case use the original presentation style (UIModalPresentationNone signals no adaptation)
        return UIModalPresentationNone;
    }
    

    UIModalPresentationNone 告诉演示控制器使用原始演示样式,在您的情况下将显示一个弹出框。

    【讨论】:

    • 这在 Xcode 7 中不再有效。文档现在声明您只能从此方法返回 FullScreen 和 OverFullScreen。
    • 实际上,我正在研究与您提到的方法相似的方法。包含traitCollection 的方法未在文档中列出。但是,唉,这对我不起作用,因为它没有在 iPhone 6 Plus 横向上调用该方法,但是在旋转时它确实调用了该方法。在纵向模式下,它确实会在呈现时调用它,但返回 .None 会导致呈现在全屏而不是弹出窗口中。
    • 没关系,这仍然按预期工作。问题是我在设置委托之前展示了它(这是文档所说的应该做的)。在呈现之前设置其popoverPresentationController 的代表解决了问题。
    • @Joey 我在 iPhone 6 Plus、横向模式、iOS 9 上遇到了同样的问题(在 iOS 8 上工作正常),我首先设置代理,然后显示。可能是什么原因?
    猜你喜欢
    • 2015-01-27
    • 2014-11-05
    • 1970-01-01
    • 1970-01-01
    • 2015-09-04
    • 1970-01-01
    • 2015-08-03
    • 2014-11-13
    • 1970-01-01
    相关资源
    最近更新 更多