【发布时间】:2013-04-18 09:02:31
【问题描述】:
我一直在尝试绘制一个简单的矩形并为边缘颜色设置动画。我尝试使用following 链接,但仍然没有帮助。我最终通过更改图层的边框颜色和动画来修复它。效果很好。
strokeColor 是否有 KVO,因为我正在让它为层的 backgroundColor 工作。
我在 XCode 4.6 上运行 iOS SDK 6.1
这就是我一直在做的:
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);
【问题讨论】:
-
等等,你是在drawRect里面添加动画吗? ????