【发布时间】:2020-05-14 15:34:43
【问题描述】:
在我的应用程序中,我按照为 Apple 提供的示例项目 UIKitCatalog 实现了 UISearchController,代码如下:
/*
A method demonstrating how to encapsulate a `UISearchController` for presentation in, for example, a `UITabBarController`
*/
func packagedSearchController() -> UIViewController {
// Load a `SearchResultsViewController` from its storyboard.
let storyboard = UIStoryboard(name: "ViewControllerSamples", bundle: nil)
guard let searchResultsController = storyboard.instantiateViewController(withIdentifier: SearchResultsViewController.storyboardIdentifier) as? SearchResultsViewController else {
fatalError("Unable to instatiate a SearchResultsViewController 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. iceland)", comment: "")
// Contain the `UISearchController` in a `UISearchContainerViewController`.
let searchContainer = UISearchContainerViewController(searchController: searchController)
searchContainer.title = NSLocalizedString("Search", comment: "")
// Finally contain the `UISearchContainerViewController` in a `UINavigationController`.
let searchNavigationController = UINavigationController(rootViewController: searchContainer)
return searchNavigationController
}
此实现在我的应用程序中运行良好,但具有想要避免的 SearchBar 和键盘的自动隐藏行为,这可能吗?以及如何?
【问题讨论】:
-
你找到解决办法了吗??
-
不,实际上我的 tvOS 应用程序存在这种行为。
-
对于其他页面,我可以接受 tvOS 的默认行为。但是对于我的应用程序的搜索页面,我不希望搜索栏和键盘自动隐藏。 Youtube 正在这样做。他们的搜索栏和键盘不会隐藏。我需要同样的行为
标签: uikit uisearchbar tvos uisearchcontroller uikeyboard