我有一个简单的 tableViewController
、一个带范围的 searchBar
和一个 navigationBar
。
当我点击我的 searchBar
时,我会看到我的示波器和所有作品。然后我单击一行并转到我的 DetailPage
并且搜索栏没有隐藏(我不知道为什么)。
所以我单击取消,然后返回到我的tableView
。当我返回到我的 tableView 时,我的 SearchBar
和我的 NavigationBar
之间有一个空白区域。
这是我的代码:
self.resultSearchController = ({
let controller = UISearchController(searchResultsController: nil)
controller.searchResultsUpdater = self
controller.hidesNavigationBarDuringPresentation = true
controller.dimsBackgroundDuringPresentation = false
controller.searchBar.sizeToFit()
controller.searchBar.scopeButtonTitles = ["Title", "Author", "Location", "Price", "User"]
self.tableView.tableHeaderView = controller.searchBar
return controller
})()
func updateSearchResults(for searchController: UISearchController)
{
let scopes = resultSearchController.searchBar.scopeButtonTitles
let currentScope = scopes![resultSearchController.searchBar.selectedScopeButtonIndex] as String
filterContentForSearchText(searchText: searchController.searchBar.text!, scope: currentScope)
}
最佳答案
尝试添加
self.automaticallyAdjustsScrollViewInsets = false;
self.extendedLayoutIncludesOpaqueBars = true
在 viewDidload
中。
关于ios - 搜索栏和导航栏之间的空白 - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39718958/