gpt4 book ai didi

ios - 如何在滚动条上隐藏搜索栏? (没有 UITableViewController)

转载 作者:行者123 更新时间:2023-11-28 07:25:27 25 4
gpt4 key购买 nike

我有一个包含 UITableView 的简单 UIViewController,我想在滚动 UITableView 时隐藏导航栏内的搜索栏。我找到了

navigationItem.hidesSearchBarWhenScrolling = true

但它不起作用。有什么方法可以让它在 UIViewController 上工作吗?

最佳答案

SWIFT 4 simple implementation

UISearchBarDelegate 委托(delegate)添加到您的类中

然后在你的类中添加这个函数

func showSearchBar() {
let searchController = UISearchController(searchResultsController: nil)
searchController.searchBar.delegate = self
searchController.dimsBackgroundDuringPresentation = false
searchController.hidesNavigationBarDuringPresentation = true
navigationItem.hidesSearchBarWhenScrolling = true
//true for hiding, false for keep showing while scrolling
searchController.searchBar.sizeToFit()
searchController.searchBar.returnKeyType = UIReturnKeyType.search
searchController.searchBar.placeholder = "Search here"
navigationItem.searchController = searchController
}

然后调用viewDidLoad()中的函数

关于ios - 如何在滚动条上隐藏搜索栏? (没有 UITableViewController),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56747186/

25 4 0