0
votes

I'm implementing UISearchController as part of the navigation item in iOS 11. This, in general, works fine. But I need to know when the searchBar is shown or hidden automatically via scrolling. None of the delegate methods in UISearchController or UISearchBar provide this information. The isActive property in UISearchController is only true when the searchBar gets focus (first responder).

The only way I've found is to use KVO on the height searchBar frame but that seams rather extreme for something like this.

Related to my requirement is also the ability to programmatically hide the searchBar (as if the user had scrolled up). The only way I've found to do this is by setting the navigation item's UISearchController property to nil but that also seems rather extreme.

Thanks.

1

1 Answers

0
votes

Easiest way to do this is adding the searchBar inside the scroll view (table view) on top of the cell(s):

enter image description here

And you can identify searchBar shown or hidden using offset value. This is not perfect way to do it but it helps to achieve your need.