Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Implicit Animation of CATextLayer.string Property

I have a view with one sublayer of type CATextLayer. I override the views drawRect: method and in there change the CATextLayer.string property to an instance of NSAttributedString. Each time the NSAttributedString has the same text but with different colors. As of now each time the string property changes, the text color makes an animated transition into the new color.

Is there any way I can disable the animation of this property?

like image 402
Antoni Avatar asked Jan 21 '23 09:01

Antoni


1 Answers

Figured it out, using the answer for this question: Disabling implicit animations in -[CALayer setNeedsDisplayInRect:]

In my particular case, to stop the changing of the CATextLayer.string property from being animated, this code was enough:

NSDictionary *newActions = [[NSDictionary alloc] initWithObjectsAndKeys:[NSNull null], @"contents", nil];
textLayer.actions = newActions;
[newActions release];

In other words, it seems that the contents key disables animations on changes to the CATextLayer.string property.

like image 189
Antoni Avatar answered Jan 22 '23 22:01

Antoni