Created
March 19, 2015 18:48
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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