Animating the foregroundColor property of the CATextLayer

I want to animate the text color change (foregroundColor) of CATextLayer on iPhone. According to the documentation, implicit animation of a property is not available in OSX 10.6, but iOS is not mentioned. As a result, I just assumed that the animation should be explicit for iOS.

I changed the class of the support layer with +(class)layerClassand set the initial value for the property in the UIView method init. The text is displayed very well, as well as all the properties that I applied (shadow, font, etc.), but the animation has no effect.

The following is my animation method, which I call from the KVO observation method, so that the view alerts the user when the observed property changes.

-(void) animateTextChange{
    animation = [CABasicAnimation animationWithKeyPath:@"foregroundColor"];

    [animation setFromValue:[[UIColor blackColor] CGColor]];

    [animation setToValue:[[UIColor whiteColor] CGColor]];

    [animation setDuration:2.0f];

    [[self layer] addAnimation:animation
                        forKey:@"foregroundColor"
 ];
}

Thanks, as always.

+5
1

, :

       [CATransaction begin];
       [CATransaction setAnimationDuration:.5];
       [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
       [CATransaction setAnimationTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
        yellowWord.foregroundColor =[UIColor redColor].CGColor;
        [CATransaction commit];

, -

+3

All Articles