I upgraded to XCode 8.0 / iOS 10 and now the color change animation of my navigation bar is not working anymore, it changes the color directly without any animation.
UIView.animateWithDuration(0.2, animations: {
self.navigationController?.navigationBar.barTintColor = currentSection.color!
})
Anyone knows how to fix this?
To animate navigationBar’s color change in iOS10 you need to call layoutIfNeeded
after setting color inside animation block.
Example code:
UIView.animateWithDuration(0.5) {
self.navigationController?.navigationBar.barTintColor = UIColor.redColor()
self.navigationController?.navigationBar.layoutIfNeeded()
}
Also I want to inform that Apple doesn’t officialy support animations in such properties like barTintColor, so that method can break at any time.
If you call -layoutIfNeeded on the navigation bar during the animation block it should update its background properties, but given the nature of what these properties do, there really hasn't ever been any kind of guarantee that you could animate any of them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With