【发布时间】:2014-10-27 00:55:39
【问题描述】:
我无法弄清楚如何让动画正常工作。我有一个名为 BallView 的 UIView 。我可以很好地画一个大的红色圆圈。我希望那个圆圈从红色变为绿色。我在视图的初始化程序中设置了CAShapeLayer 和CABasicAnimation,但动画不起作用。这是我的初始化程序:
- (void)initHelper:(UIColor*)c {
CAShapeLayer* sl = (CAShapeLayer*) self.layer;
sl.fillColor = [UIColor redColor].CGColor;
sl.path = [[UIBezierPath bezierPathWithOvalInRect:self.bounds] CGPath];
CABasicAnimation *colorAnim = [CABasicAnimation animationWithKeyPath:@"fillColor"];
colorAnim.duration = 5.0;
colorAnim.fromValue = [UIColor redColor];
colorAnim.toValue = [UIColor greenColor];
colorAnim.repeatCount = 10;
colorAnim.autoreverses = YES;
[sl addAnimation:colorAnim forKey:@"fillColor"];
}
【问题讨论】:
-
你在哪里调用了这个方法?是BallView的初始化方法吗?
-
我重写了其他初始化方法。这些 init 方法调用 initHelper。
标签: ios core-animation