简体   繁体   English

Popover涵盖了整个屏幕的iOS

[英]Popover covers entire screen iOS

I am trying to implement a popover whose anchor is a bar button item for my iphone app. 我正在尝试实现一个弹出窗口,其锚点是我的iPhone应用程序的酒吧按钮项。 I have connected the bar button item to the view controller via a segue pathway configured as show as "present as popover." 我已通过配置为显示为“呈现为弹出窗口”的segue路径将bar按钮项连接到视图控制器。 I have also set my own size for the view controller and selected "use preferred explicit size." 我还为视图控制器设置了自己的大小,并选择了“使用首选的显式大小”。 Based on previous posts about this similar topic, I have implemented the following code for my popover. 基于有关该类似主题的先前文章,我为弹出窗口实现了以下代码。 However, the popover is still covering the entire screen, probably because my adaptivePresentationStyle method is not being called ("hello" does not print to the screen). 但是,弹出窗口仍会覆盖整个屏幕,这可能是因为未调用我的adaptivePresentationStyle方法(“ hello”未打印到屏幕上)。 Note that I have also implemented the UIPopoverPresentationControllerDelegate. 请注意,我还实现了UIPopoverPresentationControllerDelegate。 Where did I go wrong? 我哪里做错了?

        override func prepare (for segue: UIStoryboardSegue, sender: Any?) {

        if segue.identifier == "popoverLogin" {

        let popoverViewController = segue.destination
        popoverViewController.modalPresentationStyle = UIModalPresentationStyle.popover
        popoverViewController.popoverPresentationController!.delegate = self         }
}

// MARK: - UIPopoverPresentationControllerDelegate method
func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
    // Force popover style
    print ("hello")
    return UIModalPresentationStyle.none
        }

Thanks! 谢谢!

In my case your code works and popover is presented normally! 就我而言,您的代码有效,弹出窗口正常显示!

在此处输入图片说明

Make sure your segue has the right "Kind": "Present As Popover". 确保您的搜索具有正确的“种类”:“作为弹出窗口呈现”。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM