我尝试用搜索栏显示推动子视图控制器,在动画期间出现闪烁的灰色条(参见图2),我该如何修复该动画?谢谢。
码:
override func viewDidLoad() {
super.viewDidLoad()
if title == nil {
title = "Title"
}
if #available(iOS 11.0, *) {
navigationController?.navigationBar.prefersLargeTitles = true
navigationItem.searchController = searchController
}
definesPresentationContext = true
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
let vc = ViewController()
vc.hidesBottomBarWhenPushed = true
navigationController?.pushViewController(vc, animated: true)
}
如果你试图push
与ViewController()
嵌入相同的NavigationController
,你看到的那个酒吧可能是你的navigationBar
的ViewController()
。
尝试创建一个新的控制器,然后push
查看该栏是否仍然存在,如下所示:
class NewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .red
}
}
然后在你的ViewController的didSelectRowAt
中,推送NewController
,如下所示:
let newVC = NewController()
navigationController?.pushViewController(newVC, animated: true)