Animate nav bar title text change

前端 未结 5 1736
孤独总比滥情好
孤独总比滥情好 2020-12-08 16:51

In my app, I have a page view controller that allows the user to swipe between different \"sections\" of the app, and at the top in the nav bar I change the title text to th

5条回答
  •  北海茫月
    2020-12-08 17:18

    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
    

提交回复
热议问题