【发布时间】:2012-08-25 14:01:26
【问题描述】:
我使用this previous 线程的答案在CAShapeLayer 上为闪烁的笔划设置动画一直不成功,经过多次搜索后,我找不到其他使用CABasicAnimation 为笔划设置动画的示例。
我想要做的是让我的CAShapeLayer 脉冲在两种颜色之间。将CABasicAnimation 用于不透明度效果很好,但[CABasicAnimation animationWithKeyPath:@"strokeColor"] 让我无法理解,我会很感激有关如何成功实施的任何建议。
CABasicAnimation *strokeAnim = [CABasicAnimation animationWithKeyPath:@"strokeColor"];
strokeAnim.fromValue = (id) [UIColor blackColor].CGColor;
strokeAnim.toValue = (id) [UIColor purpleColor].CGColor;
strokeAnim.duration = 1.0;
strokeAnim.repeatCount = 0.0;
strokeAnim.autoreverses = NO;
[shapeLayer addAnimation:strokeAnim forKey:@"animateStrokeColor"];
// CABasicAnimation *opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
// opacityAnimation.fromValue = [NSNumber numberWithFloat:0.0];
// opacityAnimation.toValue = [NSNumber numberWithFloat:1.0];
// opacityAnimation.duration = 1.0;
// opacityAnimation.repeatCount = 0.0;
// opacityAnimation.autoreverses = NO;
// [shapeLayer addAnimation:opacityAnimation forKey:@"animateOpacity"];
取消注释不透明度动画会导致预期的不透明度褪色。笔画动画不产生任何效果。隐式 strokeColor 更改按预期进行动画处理,但我希望确认 strokeColor 可以使用 CABasicAnimation 显式动画化。
更新:具体问题是 shapeLayer.path 为 NULL。更正它解决了问题。
【问题讨论】:
-
逃避你...怎么办?你试过什么?它怎么不工作?会发生什么?
标签: objective-c ios core-animation cashapelayer