我無法搞清楚如何讓動畫工作。我有一個名爲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