当我在iOS(iPhone X)中滚动时,导航栏(具有搜索控制器)的底线闪烁。尝试了许多解决方案,但没有一个起作用。这是我的代码:
(我不使用情节提要)
AppDelegate
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
}
TabBarController
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]
}
}
ViewController
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
}
}
我们将不胜感激。
答案 0 :(得分:0)
我发现了同样的问题,我想这是Apple的一个错误。但是无论如何,只要有帮助,制作导航栏isTranslucent = false
就能避免这种丑陋的行为。