How to dismiss a popover only with a button in swi

2019-09-02 17:28发布

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.

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.

1条回答
对你真心纯属浪费
2楼-- · 2019-09-02 17:49

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
        }
    }

For the delay function, see dispatch_after - GCD in swift?.

查看更多
登录 后发表回答