How to detect a click on a gray (darkened) background in UISearchDisplayController

I am working on an iOS project where I want to implement a search function. I use UISearchBarand UISearchDisplayController, and I would like to make a hidden hide UISearchBar. When the user clicks on UIBarButtonItem, the search bar and "startFirstResponder" appear, whereas when the user clicks the button Cancelon the search bar, it should disappear.

Appearance works correctly, but I have a problem with extinction. I managed to hide the search bar when the user clicked the button Cancel(method searchBarCancelButtonClicked), but I can’t hide the search bar when listening to the gray (darkened) background in UISearchDisplayController. As far as I know, there is no way to detect this event, so some hacks need to be applied. Do you know anything, or what is best discovered on a gray background?

+5
source share
2 answers

So, I finally understood everything. Besides searchBarCancelButtonClicked:(UISearchBar *)searchBar, you also need to hide the search bar in searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller. It looks like this callback is called even when a gray (dull) background is tapped, so it can be easily used to hide the search bar.

+5

UISearchDisplayController UISegmentedControl, UIResultsTable . - , . , , UIButton , , , , UIGestureRecognizer , ? , , !

0

All Articles