UISearchController doesn't work properly with a non-translucent UINavigationBar UISearchController doesn't work properly with a non-translucent UINavigationBar ios ios

UISearchController doesn't work properly with a non-translucent UINavigationBar


It's clearly a bug (rdar://20942583).

My workaround is to set

self.edgesForExtendedLayout = UIRectEdgeAll;self.extendedLayoutIncludesOpaqueBars = YES;

This allows you to keep the navigation bar opaque. The downside is that the content flows below the bar even if it can't be seen, creating some overhead.


All I needed was:

func viewDidLoad() {     extendedLayoutIncludesOpaqueBars = true}


One workaround for this is to make the status bar translucent just before the search is going to become active, and remove the translucency when the search is about become inactive.

You can do this by registering your view controller as a delegate of UISearchController, and implementing the willPresentSearchController and willDismissSearchController methods. For example (in Swift):

Declare your view controller as a delegate of UISearchController:

 class MyViewController: UITableViewController, UISearchControllerDelegate

Don't forget to actually set it as the delegate, for instance in viewDidLoad add:

    searchController.delegate = self

And finally:

func willPresentSearchController(searchController: UISearchController) {    navigationController?.navigationBar.translucent = true}func willDismissSearchController(searchController: UISearchController) {    navigationController?.navigationBar.translucent = false}