如何仅用一个按钮快速消除弹出窗口 [英] How to dismiss a popover only with a button in swift

查看:122
本文介绍了如何仅用一个按钮快速消除弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的iPad应用程序具有多个数据收集弹出窗口,并且我希望能够通过触摸它的外部来禁用弹出窗口的关闭,然后我将使用一个按钮,由用户自行决定退出该弹出窗口.

My iPad app has several data gathering popovers, and I want to be able to disable the dismissal of the popover by touching outside of it, I then will use a button to quit the popover at the users discretion.

该应用程序看起来不错,弹出窗口工作正常,并且其中有一个按钮可以很好地退出.只有我找不到在Swift中禁用解雇的方法,在obj-c上有很多帖子,但是在Swift中什么都没有.

The app looks great, the popovers work fine, and I have a button inside them that quits nicely. Only I can't find a way of disabling dismissal in Swift, lots of posts on obj-c but nothing in Swift.

这是否意味着该功能不再可用?

Does this mean that the functionality is no longer available?

非常感谢您为我的挫败感提供帮助.

I would greatly appreciate any help to my frustration.

推荐答案

只需将视图控制器的modalInPopover设置为true,将弹出窗口的passthroughViews设置为nil.但是您必须使用延迟的性能来执行后者,否则将无法正常工作.只需稍作延迟.示例:

Simply set the view controller's modalInPopover to true and the popover's passthroughViews to nil. But you must do the latter using delayed performance or it won't work. A small delay is all that's needed. Example:

    let vc = UIViewController()
    vc.modalPresentationStyle = .Popover
    self.presentViewController(vc, animated: true, completion: nil)
    if let pop = vc.popoverPresentationController {
        vc.modalInPopover = true
        delay(0.1) {
            pop.passthroughViews = nil
        }
    }

有关delay功能,请参见 dispatch_after-快速运行GCD吗?.

这篇关于如何仅用一个按钮快速消除弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆