Description
In my tvOS application, I have a search page on top of a Search Bar
and below Table View
with a possible list of results.
While we are focusing searchBar
and the user clicks the voice for Siri, the results are inserted into the search bar (as expected). However, when the user scrolls the results and cannot find what he is looking for, they need to scroll up (completely back) to searchBar
to use Siri again.
If the user tries to use Siri, but is searchBar
NOT in focus, the global Siri starts looking for results in different applications (this is not what I want)
Question:
How to set searchBar as global focus for Siri on search page?
What I tried:
Honestly, I have no idea how to do this.
In AppDelegate.swift, a function is called to create a search controller and add it to the controller of the tab bar.
I thought about trying preferredFocusView, but after reading the documentation, I doubt that you are going to work.
func configueSearchController() -> UIViewController {
let storyboard = UIStoryboard(name: "Search", bundle: nil)
guard let searchResultsController = storyboard.instantiateViewController(withIdentifier: SearchViewController.storyboardIdentifier) as? SearchViewController else {
fatalError("Unable to instatiate a SearchResultViewController from the storyboard.")
}
let searchController = UISearchController(searchResultsController: searchResultsController)
searchController.searchResultsUpdater = searchResultsController
searchController.searchBar.placeholder = NSLocalizedString("Enter keyword (e.g. Gastric Bypass)", comment: "")
searchController.view.backgroundColor = Constants.Color.backgroundcolor
searchController.searchBar.keyboardAppearance = UIKeyboardAppearance.dark
searchController.searchBar.tintColor = Constants.Color.backgroundcolor
searchController.searchBar.backgroundColor = Constants.Color.backgroundSearchBarColor
searchController.searchBar.setTextColor(color: .white)
searchController.hidesNavigationBarDuringPresentation = false
searchController.obscuresBackgroundDuringPresentation = true
searchController.searchBar.searchBarStyle = .minimal
searchController.searchBar.sizeToFit()
searchController.searchBar.focus
searchController.searchBar.accessibilityLanguage = "en"
let searchContainer: UISearchContainerViewController = UISearchContainerViewController(searchController: searchController)
let searchNavigationController = UINavigationController(rootViewController: searchContainer)
searchNavigationController.navigationBar.isTranslucent = true
searchNavigationController.navigationBar.tintColor = Constants.Color.backgroundcolor
searchNavigationController.tabBarItem.title = "Search"
return searchNavigationController
}
source
share