0

In my app, I have a Popover which is spawned from a UIBarButtonItem in a UIToolbar. Currently, it is possible to tap the other buttons in the UIToolbar when the Popover is being shown.

How do I still dismiss the Popover when tapping outside it while also not allowing the user to tap on UIViews outside the Popover? Do I just need to disable the views external to the Popover?

// prepare Actions Menu
let storyboard = UIStoryboard(name: "Main", bundle: nil)

actionsVC = storyboard.instantiateViewController(withIdentifier: "actionsViewController") as! ActionsController
actionsVC.modalPresentationStyle = .popover
actionsVC.graph = graph
actionsVC.viewControllerDelegate = self

...

@IBAction func openActionsPopover(_ sender: UIBarButtonItem) {
        actionsVC.popoverPresentationController?.barButtonItem = sender
        actionsVC.popoverPresentationController?.passthroughViews?.removeAll()
        present(actionsVC, animated: true)
}
  • 3
    Update your question with relevant code showing how you create, setup, and display your popover. – rmaddy Mar 19 '18 at 16:17
  • Possible duplicate of [is there a way NOT to have the popover dismissed when pressing outside it?](https://stackoverflow.com/questions/5477422/is-there-a-way-not-to-have-the-popover-dismissed-when-pressing-outside-it) – Maximelc Mar 19 '18 at 16:55
  • Added code samples. Attempted the solution given in the other question but it had no effect. – Dillon Fagan Mar 19 '18 at 17:34

1 Answers1

0

Check passthroughViews and modalInPopover property.

Maximelc
  • 2,384
  • 1
  • 21
  • 17
  • Would this then mean that the other UIViews in the toolbar are somehow being added to passthroughViews by default? – Dillon Fagan Mar 19 '18 at 17:30
  • By default not, an other solution should be to disable the others buttons while your popover is visible using `myBarButtonItem.isEnabled = false` – Maximelc Mar 19 '18 at 17:33
  • Yeah, that's what I was thinking but I didn't think it seemed quite right since that would mean setting .isEnabled = false for each UIView. Seems a bit inefficient... – Dillon Fagan Mar 19 '18 at 17:35
  • Yeah you right, read this answer https://stackoverflow.com/a/30944872/2370587 it can help you. – Maximelc Mar 19 '18 at 17:37
  • That didn't work. Setting isModalInPopover to true simply disabled dismissal of the popover by tapping outside it. I still want the popover to be dismissed when tapping outiside of it. I just don't want the user to be able to tap on other buttons when the popover is open. – Dillon Fagan Mar 19 '18 at 17:45
  • Okay so it's possible to trick this using a UITapGestureRecognizer, add this gesture to your main view and for the action simply dismiss the popover. – Maximelc Mar 19 '18 at 18:02