How to dismiss a popover only with a button in swift

一个人想着一个人 提交于 2019-12-12 06:19:13

问题


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:


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?.



来源:https://stackoverflow.com/questions/30944684/how-to-dismiss-a-popover-only-with-a-button-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!