ios - 在视图控制器与搜索控制器搜索栏之间导航隐藏和显示有 ui 故障
问题描述
我用过简单UISearchController
的UITableViewController
. 当我在第一个控制器中使用搜索栏并且隐藏在下一个或后退中时,这会出现问题,它会显示 UI 故障。
下面是设置导航栏的代码。
self.extendedLayoutIncludesOpaqueBars = true
let navigationBar = navigationController.navigationBar
let navigationBarTitleTextAttritbutes = [NSAttributedString.Key.foregroundColor: UIColor.white]
navigationBar.titleTextAttributes = navigationBarTitleTextAttritbutes
if #available(iOS 11.0, *) {
navigationBar.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
navigationBar.prefersLargeTitles = false
}
navigationBar.isTranslucent = false
navigationBar.tintColor = UIColor.white
navigationBar.barTintColor = UIColor.purple
并用于设置搜索控制器,如下所示
self.searchController = UISearchController(searchResultsController: nil)
self.searchController.dimsBackgroundDuringPresentation = false
self.searchController.hidesNavigationBarDuringPresentation = false
self.searchController.hidesBottomBarWhenPushed = true
self.searchController.obscuresBackgroundDuringPresentation = false
let searchBarObj = self.searchController.searchBar
searchBarObj.delegate = self as? UISearchBarDelegate
searchBarObj.placeholder = "Search here"
searchBarObj.isTranslucent = false
searchBarObj.tintColor = .white
if #available(iOS 11.0, *) {
searchBarObj.tintColor = .white
searchBarObj.barTintColor = .white
navigationItem.searchController = searchController
navigationItem.hidesSearchBarWhenScrolling = true
} else {
let tintColor = UIColor.purple
searchBarObj.barTintColor = tintColor
searchBarObj.layer.borderColor = tintColor.cgColor
searchBarObj.layer.borderWidth = 1
if let table = tableview {
table.tableHeaderView = searchController.searchBar
}
}
解决方案
推荐阅读
- memory - 获取存储在地址空间中的内存
- javascript - React Native 中的第一个数据中来自 API responseJson 的未定义数据
- swift - iOS Application Support 目录默认存在于设备上
- python - 鉴于其内容,将列表中的项目替换为几个选项之一
- google-apps-script - 当单元格具有两个定义的文本值之一时,Google 表格运行脚本
- c++ - 为没有 qmake/VS 的 Qt Windows 应用程序设置 .exe 图标
- c - 当给定字母的字典顺序时,合并排序的时间复杂度是多少?
- google-data-studio - 有没有办法将当前时间戳添加到 Google Data Studio 报告中?
- android - 在 textView 中打印一个 json 文件
- javascript - 在 Jquery 中的单击功能在计算机上使用时不起作用