ios - 带有UITabBarController的searchBarController的导航栏在更改导航栏的颜色时闪烁
问题描述
当我在 iOS (iPhone X) 中滚动时,导航栏的底线(具有搜索控制器)闪烁。尝试了许多解决方案,但都没有奏效。这是我的代码:
(我没有使用故事板)
应用委托
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
self.window = UIWindow()
let viewCtrl = TabController()
let navCtrl = UINavigationController(rootViewController: viewCtrl)
self.window?.rootViewController = navCtrl
self.window?.makeKeyAndVisible()
return true
}
标签栏控制器
class TabController: UITabBarController {
init() {
super.init(nibName: nil, bundle: nil)
self.viewControllers = [ViewController()]
self.navigationItem.searchController = UISearchController(searchResultsController: nil)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.navigationBar.barTintColor = .white
navigationController?.navigationBar.tintColor = .white
navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
}
}
视图控制器
class ViewController: UITableViewController {
init() {
super.init(nibName: nil, bundle: nil)
self.view.backgroundColor = .white
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 100
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
cell.textLabel?.text = "Test"
return cell
}
}
帮助将不胜感激。
解决方案
我发现了同样的问题,我认为是 Apple 的错误。但无论如何,如果有帮助,制作导航栏isTranslucent = false
可以帮助避免这种丑陋的行为。
推荐阅读
- sql - oracle 日期格式比较 ORA-01858
- concourse - 无法在大厅中使用 gcs-resource 一个接一个地触发作业
- angular - 在执行 onclick 函数之前禁用元素属性
- android - 将子视图保留在 ConstraintLayout 中的布局内
- php - PHP 7.2 json_decode()
- java - Log4j 属性被忽略
- .net-core - 在 Visual Studio 2017 中打开解决方案后如何防止 nuget 冗余还原包
- javascript - jquery ReferenceError:未将变量定义为数组索引
- c# - Dapper 和 n 层应用程序(导航属性)
- python - Python 烧瓶应用程序在启动 ImportError 时抛出以下错误:不支持按文件名导入