通过Swift滚动隐藏/取消隐藏UISearchBar

时间:2018-09-16 15:43:51

标签: ios swift xcode scroll uisearchbar

我需要建议,在滚动tableView时如何隐藏/取消隐藏此搜索栏?

这是我的代码:

private let searchController = UISearchController(searchResultsController: nil)

和设置方法:

private func setupSearchController() {

    searchController.searchResultsUpdater = self
    if #available(iOS 9.1, *) {
        searchController.obscuresBackgroundDuringPresentation = false
    } else {
        // Fallback on earlier versions
    }
    searchController.searchBar.placeholder = " "

    if #available(iOS 11.0, *) {
        navigationItem.searchController = searchController
        navigationItem.hidesSearchBarWhenScrolling = false
        searchController.obscuresBackgroundDuringPresentation = false
    } else {
        // Fallback on earlier versions
    }
    definesPresentationContext = true
    self.automaticallyAdjustsScrollViewInsets = false
}

我猜想,其他方法确实很重要。那么设置中缺少什么?

1 个答案:

答案 0 :(得分:0)

您尝试过

navigationItem.hidesSearchBarWhenScrolling = true