1

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.

matt
  • 515,959
  • 87
  • 875
  • 1,141
Midaero
  • 65
  • 2
  • 5

1 Answers1

3

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

Community
  • 1
  • 1
matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Thank you Matt, this was a great help. The delay function was a nice little bonus. But the code is now holding in place, and I have an exit button to dismiss. nothing worse than a view quitting by accident when you are collecting 10 items of data. – Midaero Jun 19 '15 at 21:42