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];
}
答案 0 :(得分:1)
您可以添加一个CALayer,并将CALayer蒙版设置为CATextLayer,并通过动画更改CALayer backgroundColor。