在同一页面跳转时的情况
即searchController = UISearchController.init(searchResultsController: nil)
//创建searchController时
searchController = UISearchController.init(searchResultsController: nil)
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
searchController.searchBar.placeholder = "搜索"
searchController.searchBar.delegate = self
searchController.delegate = self
searchController.searchBar.sizeToFit()
myTableView.tableHeaderView = searchController.searchBar
self.definesPresentationContext = true;
出现如上情况,是因为searchBar的frame改变导致,tableView的hearder
也需要跟随变化
func didPresentSearchController(_ searchController: UISearchController) {
self.myTableView.frame = CGRect.init(x: 0, y: 20, width: ScreenWidth(), height: ScreenHeight()-20)
myTableView.tableHeaderView?.bounds = searchController.searchBar.frame
}
func didDismissSearchController(_ searchController: UISearchController) {
self.myTableView.frame = CGRect.init(x: 0, y: 0, width: ScreenWidth(), height: ScreenHeight()-64)
myTableView.tableHeaderView?.bounds = searchController.searchBar.frame
}
即可解决