Skip to content

Instantly share code, notes, and snippets.

@ryanmasondavies
Created March 19, 2015 18:48
Show Gist options
  • Save ryanmasondavies/da78f4b2be0a7e490ddd to your computer and use it in GitHub Desktop.
Save ryanmasondavies/da78f4b2be0a7e490ddd to your computer and use it in GitHub Desktop.
Custom subclass of UISearchDisplayController that overrides the default behaviour of hiding the navigation bar when becoming active.
import UIKit
/** Custom subclass of UISearchDisplayController that overrides the default behaviour of hiding the navigation bar when becoming active. */
class SearchDisplayController: UISearchDisplayController {
override func setActive(visible: Bool, animated: Bool) {
if self.active == visible {
return
}
searchContentsController.edgesForExtendedLayout = .Bottom
if let navigationController = searchContentsController.navigationController {
navigationController.setNavigationBarHidden(true, animated: false)
}
super.setActive(visible, animated: animated)
if let navigationController = searchContentsController.navigationController {
navigationController.setNavigationBarHidden(false, animated: false)
}
if visible {
searchBar.becomeFirstResponder()
} else {
searchBar.resignFirstResponder()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment