[英]iOS - Navigation bar color transition when pressing back button
在导航堆栈中使用barTintColor时,我正在尝试更改导航栏的颜色,使用barTintColor(_:willShow:animated :)。
这是代码:
func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
if viewController is ViewerViewController {
navigationBar.barTintColor = UIColor(custom: .white)
navigationBar.tintColor = UIColor(custom: .black)
} else if viewController is FeedViewController {
navigationBar.barTintColor = UIColor(custom: .blue)
navigationBar.tintColor = UIColor(custom: .white)
}
}
当我按下视图控制器并使用滑动后退手势时,一切都很美妙(颜色过渡在两个方面都很平滑)。
但是,当我按下后退按钮时 ,颜色最初不会改变,导航过渡完成,然后颜色改变而没有动画 。
有人已经遇到/解决了这个问题吗? 任何线索将不胜感激。
我有完全相同的问题,所以用自定义左栏按钮替换了“后退”按钮,并调用:
navigationController?.popViewController(animated: true)
编辑:
设置leftBarButton导致滑动手势丢失,所以我需要另一个hack:
navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "back"), style: .plain, target: self, action: #selector(pop))
navigationController?.interactivePopGestureRecognizer?.delegate = self
我最终使用了KMNavigationBarTransition库 ,它运行良好,不需要一行代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.