Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing Popover Dismissal When Tapping Outside (Swift)

Tags:

ios

swift

popover

I am trying to prevent a popup from being dismissed when the user taps outside of the popup. I have seem other questions/answers about this, and they all seem to suggest using the modalInPopover for the view. I have done this in the viewDidAppear as I have seen suggested. I have text fields along with buttons that fill in a label according to a selection from a dropdown menu. Before any information is entered, it works fine, and the popup is not dismissed when tapping outside. It also works fine for when text is entered in the text fields. However, as soon as I make a selection from a dropdown after tapping one of the buttons, the popup will dismiss after touching outside of it.

Are there any other suggestions as to why this could be? Could it have something to do with calling resignFirstResponder on the text fields?

like image 329
mhunt2015 Avatar asked Aug 30 '16 19:08

mhunt2015


People also ask

How to dismiss the Popover when on an outside click?

Let's look at the two simplest ways of dismissing the popover. You can pass the additional prop rootClose to your OverlayTrigger component to dismiss the popover when on an outside click. 1 ... 2 <OverlayTrigger trigger="click" rootClose placement="right" overlay={popover}> 3 ...

How to dismiss a popover in react bootstrap?

The default dismissing action of React Bootstrap popover is the same button that triggers it. The button that opens the popover on click acts like a toggle. The user, however, expects the popover to close when they click anywhere outside the page, just like modals, due to their similar interfaces.

How do I dismiss the keyboard if the user taps anywhere?

In iOS, the keyboard doesn’t dismiss automatically if the user taps anywhere outside of the keyboard view. So, we need to handle it manually. To achieve this, we can simply add one UITapGestureRecognizer to the parent view and dismiss the keyboard if any tap detected.

What is popover and how to use it?

Popovers can be used in several ways, such as calculating the price of an inventory item in an e-commerce web app, displaying details of a new car model, etc. However, when using a UI component, be sure it is conveniently handled on the user's end.


1 Answers

In swift 3, ios 10

After implementing UIPopoverPresentationControllerDelegate the following function seems to do the trick.

func popoverPresentationControllerShouldDismissPopover(_ popoverPresentationController: UIPopoverPresentationController) -> Bool {
    return false
}

I hope this helps if anyone is still looking for a solution.

like image 119
Trevor Avatar answered Sep 21 '22 07:09

Trevor