iOS - 按下后退按钮时的导航栏颜色转换

Joh*_*Oin 7 transition colors uinavigationbar ios

在导航堆栈中使用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)
    }
  }
Run Code Online (Sandbox Code Playgroud)

当我按下视图控制器并使用滑动后退手势时,一切都很美妙(颜色过渡在两个方面都很平滑).

但是,当我按下后退按钮时,颜色最初不会改变,导航过渡完成,然后颜色改变而没有动画.

有人已经遇到/解决了这个问题吗?任何线索将不胜感激.

Joh*_*Oin 0

我最终使用了KMNavigationBarTransition 库,它工作得很好并且不需要一行代码。