用于呈现 SearchController 的代码:
searchController = UISearchController(searchResultsController:viewcontroller)
storageLocation.tableView.tableHeaderView = searchController.searchBar
searchController.dimsBackgroundDuringPresentation = true
searchController.hidesNavigationBarDuringPresentation = true
searchController.searchBar.prompt = "Some random text"
self.definesPresentationContext = true
searchController.searchBar.backgroundColor = .white
self.present(searchController, animated: true, completion: nil)
最佳答案
我认为你的 storageLocation 到顶部的间距是 -20。当您在 Storyboard中设置约束时,不要对顶部的填充感到 panic (即使您设置了 0 间距),那是状态栏的。
选项:
将 storageLocation 顶部间距设置为 0 而不是 -20
隐藏状态栏
要隐藏状态栏,请将其添加到 VC 的底部:
override var prefersStatusBarHidden: Bool {
return true
}
在您的 info.plist 中将“UIRequiresFullScreen”键设置为 YES。
在您的项目设置 -> 目标 -> 常规(您在其中设置应用程序名称、 bundle 标识符、签名等)的部署信息中,确保“选择隐藏状态栏”
关于swift - UISearch Bar 提示与状态栏重叠,同时呈现为 UISearchController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45321247/