私は単純な長方形を描き、エッジの色をアニメーション化しようとしています。次のリンクを使用してみましたが、まだ役に立ちません。レイヤーの境界線の色を変更してアニメーション化することで、最終的に修正しました。それはうまくいきました。
strokeColor
レイヤーで機能するようになっているため、KVOはありますかbackgroundColor
。
iOS SDK 6.1を実行しているXCode 4.6を使用しています
これは私がやっていることです:
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 2.0);
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
CABasicAnimation *strokeAnim = [CABasicAnimation animationWithKeyPath:@"strokeColor"];
strokeAnim.fromValue = (id) [UIColor redColor].CGColor;
strokeAnim.toValue = (id) [UIColor greenColor].CGColor;
strokeAnim.duration = 3.0;
strokeAnim.repeatCount = 0;
strokeAnim.autoreverses = YES;
[self.layer addAnimation:strokeAnim forKey:@"animateStrokeColor"];
CGContextMoveToPoint(context, 0, 0);
CGContextAddLineToPoint(context, squareLength, 0);
CGContextAddLineToPoint(context, squareLength, squareLength);
CGContextAddLineToPoint(context, 0, squareLength);
CGContextAddLineToPoint(context, 0, 0);
CGContextStrokePath(context);