Description
In my tvOS application, I have a search page with on top a Search Bar
and under a Table View
with the eventual list of results.
While we are focusing the searchBar
and the user presses the voice for Siri, the results get inserted into the Search Bar (as expected). However, when the user is scrolling down through the results and is unable to find what they're looking for, they have to scroll up (all the way back up) to the searchBar
to use Siri again.
If the user attempts to use Siri while the searchBar
is NOT in focus, a global Siri starts looking for results in different apps (which is not what I want)
Question:
How to set the searchBar as the global focus for Siri on the Search Page?
What I've tried:
To be honest I have no idea how to go about this..
A function is called in AppDelegate.swift to create the Search View Controller and add it to the Tab Bar Controller.
I've thought about trying preferedFocusView but after reading the documentation, I doubt that's 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.")
}
/*
Create a UISearchController, passing the `searchResultsController` to
use to display search results.
*/
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
//TODO: Check if this works
searchController.searchBar.accessibilityLanguage = "en"
//searchResultsController.tableView.tableHeaderView = searchController.searchBar
// Contain the `UISearchController` in a `UISearchContainerViewController`.
let searchContainer: UISearchContainerViewController = UISearchContainerViewController(searchController: searchController)
// Finally contain the `UISearchContainerViewController` in a `UINavigationController`.
let searchNavigationController = UINavigationController(rootViewController: searchContainer)
searchNavigationController.navigationBar.isTranslucent = true
searchNavigationController.navigationBar.tintColor = Constants.Color.backgroundcolor
searchNavigationController.tabBarItem.title = "Search"
return searchNavigationController
}
Supporting Focus in View Controllers
. developer.apple.com/library/content/documentation/General/… I believe you must have experiences in iOS. But that shouldn't make you miss the app programming guide for tvOS. – Incident