Prevent Search Bar from hiding

Asked by At

In Android Search View won't hide until you press close button ("X") which makes sense

enter image description here

But in iOS if you tap somewhere (e.g., in the center of the screen) search bar hides automatically and func searchBarCancelButtonClicked(_ searchBar: UISearchBar) isn't even called because you didn't click cancel button, you just clicked some other place

And results from that last search are still displayed and when you click search item icon again the SearchBar's text field is empty and it's really doesn't make sense

So I want to prevent search bar hiding until cancel button is pressed by a user (only cancel button should have a power to close the search bar)

enter image description here

enter image description here


Seems I found the solution:

searchController.dimsBackgroundDuringPresentation = false

But the name of this property doesn't make any sense too because it's not just about dimming background, it has two functions:

  • dims the background
  • controls if search bar should be hidden when you press some other place

0 Answers