この前のCAShapeLayer
スレッドの回答を使用してで点滅するストロークをアニメーション化することに失敗しました。多くの検索の後、 を使用してストロークをアニメーション化する他の例を見つけることができません。CABasicAnimation
私がやりたいのは、CAShapeLayer
2 つの色の間で脈拍を調整することです。CABasicAnimation
opacity の使用は問題なく機能しますが、[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 の変更は期待どおりにアニメーション化しますが、CABasicAnimation を使用して strokeColor を明示的にアニメーション化できることを文書化して確認したいと思います。
更新: 具体的な問題は、shapeLayer.path が NULL だったことです。それを修正すると、問題が修正されました。