我无法搞清楚如何让动画工作。我有一个名为BallView的UIView。我可以画一个很大的红色圆圈。我希望这个圈子从红色变为绿色。我在我的视图的初始化器中设置了CAShapeLayer
和CABasicAnimation
,但动画不起作用。这里是我的初始化:CAShapeLayer没有动画
- (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的初始化方法吗? – gabbler 2014-10-27 01:39:04
我重写了其他init方法。那些init方法调用initHelper。 – csnate 2014-10-27 01:40:38