【问题标题】:swift - Popover is not displayed correctly in landscape modeswift - 横屏模式下弹出框显示不正确
【发布时间】:2016-11-29 02:04:41
【问题描述】:

Popover 在横向模式下会占据整个屏幕,但在纵向模式下也能正常工作。此外,当我在横向模式下单击弹出框外时,它不会消失。

我通过情节提要连接了弹出框。在 popoverviewcontroller 中,我放置了一个包含按钮的视图。 popoverviewcontroller的viewdidload()的代码是:

override func viewDidLoad() {
    super.viewDidLoad()

    self.preferredContentSize = popoverView.frame.size
        }

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

肖像:

风景:

【问题讨论】:

    标签: ios swift popover


    【解决方案1】:

    您必须像这样将UIPopoverPresentationControllerDelegate添加到您的班级:

    斯威夫特 3

    import UIKit
    
    class ViewController: UIViewController, UIPopoverPresentationControllerDelegate {
        ...
    

    作为第二步,添加以下函数:

    func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
        return UIModalPresentationStyle.none
    }
    

    说明:通过将 UIModalPresentationStyle 返回为 none,保留原始演示样式,并且您的弹出框不会横向拉伸到屏幕底部。

    【讨论】:

    • 这不起作用。在横向模式下,它仍然以模态方式呈现。
    • @Ruben 查看 Markv07 的答案。 adaptivePresentationStyle 函数的 traitCollection: UITraitCollection 参数是它工作所必需的。显然是 iOS 中的一个错误。
    【解决方案2】:

    @Jake2Finn 的答案适用于 Swift 4.0

    trait 参数专门用于修复景观问题:

    traitCollection: UITraitCollection
    

    没有它,自适应功能...仅适用于纵向。

    【讨论】:

      猜你喜欢
      • 2017-09-16
      • 2014-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-03
      • 1970-01-01
      相关资源
      最近更新 更多