On iOS 15, when navigating to a view controller that has a transparent navigation bar, the animation to the transparent bar isn't working as expected.
However, if you navigate back to the view controller with a transparent navigation bar, the animation works as expected.
This is how I've set up my view controllers:
rootVC
let appearance = UINavigationBarAppearance()
appearance.configureWithDefaultBackground()
appearance.backgroundColor = UIColor.red
self.navigationController?.navigationBar.standardAppearance = appearance
self.navigationController?.navigationBar.scrollEdgeAppearance = self.navigationController?.navigationBar.standardAppearance
firstVC
let appearance = UINavigationBarAppearance()
appearance.configureWithTransparentBackground()
self.navigationController?.navigationBar.standardAppearance = appearance
self.navigationController?.navigationBar.scrollEdgeAppearance = self.navigationController?.navigationBar.standardAppearance
secondVC
let appearance = UINavigationBarAppearance()
appearance.configureWithDefaultBackground()
appearance.backgroundColor = UIColor.yellow
self.navigationController?.navigationBar.standardAppearance = appearance
self.navigationController?.navigationBar.scrollEdgeAppearance = self.navigationController?.navigationBar.standardAppearance
Notice in the following example how smooth the transition is from secondVC -> firstVC but not from rootVC -> firstVC:
Example project: https://github.com/karlingen/NavigationTest
Any ideas why it's behaving like this?
I got the following reply from Apple:
So we should be using
UINavigationItem
instead. Using the following code fixed it for me: