Animate nav bar title text change
If you want to animate between different title strings, use the following:
CATransition *fadeTextAnimation = [CATransition animation];
fadeTextAnimation.duration = 0.5;
fadeTextAnimation.type = kCATransitionFade;
[self.navigationController.navigationBar.layer addAnimation: fadeTextAnimation forKey: @"fadeText"];
self.navigationItem.title = "My new title";
You can adjust the duration and set a timing function to suit, of course.
There are also other types of animation that might work in different circumstances (thanks @inorganik):
kCATransitionFade
kCATransitionMoveIn
kCATransitionPush
kCATransitionReveal
Swift 5
let fadeTextAnimation = CATransition()
fadeTextAnimation.duration = 0.5
fadeTextAnimation.type = .fade
navigationController?.navigationBar.layer.add(fadeTextAnimation, forKey: "fadeText")
navigationItem.title = "test 123"
For convenience, Ashley Mills solution in Swift:
11/16/2016 Updated for Swift 3 (Thanks to n13)
let fadeTextAnimation = CATransition()
fadeTextAnimation.duration = 0.5
fadeTextAnimation.type = kCATransitionFade
navigationController?.navigationBar.layer.add(fadeTextAnimation, forKey: "fadeText")
navigationItem.title = "test 123"
Swift 2.x
let fadeTextAnimation = CATransition()
fadeTextAnimation.duration = 0.5
fadeTextAnimation.type = kCATransitionFade
navigationController?.navigationBar.layer.addAnimation(fadeTextAnimation, forKey: "fadeText")
navigationItem.title = "test 123"
I tip my hat to Ashley!