[英]How to dismiss a popover only with a button in swift
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. 我的iPad应用程序具有多个数据收集弹出窗口,并且我希望能够通过触摸其外部来禁用弹出窗口的关闭,然后我将根据用户的意愿使用按钮退出弹出窗口。
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. 只有我找不到在Swift中禁用解雇的方法,在obj-c上有很多帖子,但是在Swift中什么也没有。
Does this mean that the functionality is no longer available? 这是否意味着该功能不再可用?
I would greatly appreciate any help to my frustration. 我会很感激我的沮丧。
Simply set the view controller's modalInPopover
to true
and the popover's passthroughViews
to nil
. 只需将视图控制器的modalInPopover
为true
,并将弹出窗口的passthroughViews
为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
}
}
For the delay
function, see dispatch_after - GCD in swift? 有关delay
功能,请参见dispatch_after-快速启动GCD? . 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.