FlaneurSearchViewController
open class FlaneurSearchViewController: UIViewController
This class is a convenience wrapper around UISearchController
that view controllers
can subclass to inherit some behaviors.
Why this class?
If you don’t use a UITableView
or UINavigationItem
‘s searchController
introduced in iOS 11.0,
or any other immediate location for a UISearchController
’s searchBar
, and you want to use
AutoLayout, things can get weird/hacky/difficult.
This class fixes all positioning problems found in an app using a navigation controller hierarchy with hidden navigation bars, and using iOS 9.0.
It will display the search bar right under your view controller’s top layout guide.
Subclassing
To subclass this class, provide your own implementations of instanciateSearchResultsController
and searchControllerWillBecomeActive
, and call startSearchAction
when relevant.
-
This property provides the intended search results controller of
UISearchController
. Please refer toUISearchController
documentation for details.The resulting
UIViewController
will typically implementUISearchResultsUpdating
and will act as theUISearchController
‘ssearchResultsUpdater
.Declaration
Swift
public var instanciateSearchResultsController: () -> (UIViewController?) = { return nil }
-
This property can be used as a hook for the subclass to implement some custom behavior using the search controller, like styling the search bar, get information about its height, etc.
Declaration
Swift
public var searchControllerWillBecomeActive: (UISearchController) -> () = { _ in () }
-
Calling this method adds the search bar container within the view and sets up constraints to reveal the search bar when relevant.
Declaration
Swift
override open func viewDidLoad()
-
Deactivates the search controller before calling
super
.Declaration
Swift
override open func viewWillDisappear(_ animated: Bool)
-
Calls this method when the subclass is ready to show the search bar transiently (ie after a user action).
Declaration
Swift
@IBAction public func startSearchAction(_ sender: Any? = nil)
Parameters
sender
the sender of the action
-
Calls this method when the subclass is ready to show the search bar permanently.
Declaration
Swift
public func presentSearchBar()
-
Undocumented
Declaration
Swift
public func dismissSearchBar()
-
Undocumented
Declaration
Swift
public func willDismissSearchController(_ searchController: UISearchController)
-
Undocumented
Declaration
Swift
public func willPresentSearchController(_ searchController: UISearchController)
-
Undocumented
Declaration
Swift
public func searchBarSearchButtonClicked(_ searchBar: UISearchBar)