Search code examples
iphonecocoa-touchcore-animation

Keeping a Core Animation transition persistent?


I have a custom UILabel that I want to add a transition to when the text changes.

I create a transition:

CATransition *a = [CATransition animation];
a.duration = 1.0;
a.type = kCATransitionPush;
self.transition = a;

I set the transition to a property in my class. Here's the method I call to update the text:

- (void)postMessage:(NSString *)message {    
    [self.messageLabel.layer addAnimation:self.transition forKey:@"statusAnimation"];
    self.messageLabel.text = message;
}

This all works fine. However, I don't want to keep adding the animation to my label. That slows it down every time I update.

My question is - how can I keep this transition persistent so it shows an animation every single time I call this method without having to add it manually every time?


Solution

  • What you're asking isn't quite possible. Core Animation is a stateful library, and copies the animation object you present, then releases it upon completion. If you are having issues with performance, you should be using the animation block methods. This overview of Core Animation with blocks should help you get started.