Search code examples
iosobjective-ccore-animation

CATextLayer foregroundColor animation don't work on iOS9 but work on iOS10 or high


CATextLayer foregroundColor animation don't work on iOS9 but work normal on iOS10 or high version! I don't know what's wrong with my code!

Code as follow:

- (void)addAnimationOnLayer:(CATextLayer*)layer{
CABasicAnimation *colorAn = [CABasicAnimation animationWithKeyPath:@"foregroundColor"];

colorAn.fromValue = (id)NeColor333333.CGColor;
colorAn.toValue = (id)NeColor999999.CGColor;


CABasicAnimation *sizeAn = [CABasicAnimation animationWithKeyPath:@"fontSize"];
sizeAn.fromValue = @16.0;
sizeAn.toValue = @12.0;


CAKeyframeAnimation *keyAn = [CAKeyframeAnimation animationWithKeyPath:@"position"];
keyAn.values = @[[NSValue valueWithCGPoint:layer.position],[NSValue valueWithCGPoint:CGPointMake(layer.position.x, layer.position.y - 16)]];
keyAn.keyTimes =@[@0.0,@1.0];

CAAnimationGroup *group = [CAAnimationGroup animation];
group.animations = @[colorAn, keyAn, sizeAn];
group.duration = 0.4;
group.repeatCount = 1;
group.fillMode = kCAFillModeForwards;
group.removedOnCompletion = NO;

[layer addAnimation:group forKey:nil];
}

Solution

  • You can add a CALayer, and set CALayer mask is a CATextLayer, you an change CALayer backgroundColor with animation.