CATextLayer foregroundColor 动画不适用于 iOS9 但适用于 iOS10 或更高

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

CATextLayer foregroundColor 动画在 iOS9 上不起作用,但在 iOS10 或高版本上可以正常工作!我不知道我的代码有什么问题!

代码如下:

- (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];
}

你可以添加一个CALayer,并且设置CALayer mask是一个CATextLayer,你用animation改变CALayer backgroundColor。