IOS - color transition in the navigation bar when you press the back button

I am trying to change the color of the navigation bar when I click the view controller in the navigation stack using barTintColor while navigating the Controller (_: willShow: animated :).

Here is the code:

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) } } 

Everything works beautifully when I press the view controller, and when I use the rewind gesture (the color transition is smooth in both directions).

However, when I press the back button , the color does not change at first, it goes to navigation, and then the color changes without animation ... p>

Has anyone already encountered / resolved this issue? Any key would be appreciated.

+6
source share
2 answers

In the end, I used the KMNavigationBarTransition library , which works very well and does not require a separate line of code.

0
source

I had the same problem, so I replaced the back button with a user button on the left bar and called:

 navigationController?.popViewController(animated: true) 

edit:

setting leftBarButton caused the loss of swipe gestures, so I needed another hack:

 navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "back"), style: .plain, target: self, action: #selector(pop)) navigationController?.interactivePopGestureRecognizer?.delegate = self 
0
source

Source: https://habr.com/ru/post/1012299/


All Articles