当UIViewController
实施为UISearchController
self.navigationItem.searchController = search
时调整约束
推送新控制器:SearchBar折叠但在初始位置上以constrait to top = 0
离开View。
(ViewController的背景为黄色,以便于理解此事)
实现:
viewDidLoad() {
if #available(iOS 11.0, *) {
let search = UISearchController(searchResultsController: nil)
search.searchResultsUpdater = self
search.definesPresentationContext = true
search.hidesNavigationBarDuringPresentation = false
search.searchBar.tintColor = UI.COLOR_WHITE
search.dimsBackgroundDuringPresentation = false
self.navigationItem.hidesSearchBarWhenScrolling = false
self.navigationItem.searchController = search
}
我尝试使用self.automaticallyAdjustsScrollViewInsets = false
但未成功,tableView
实施self.contentInsetAdjustmentBehavior = .always
我错过了什么?非常感谢帮助。