如何在iphone或xcode中使用CAShapeLayer制作多色圆圈动画?

时间:2012-12-30 15:55:06

标签: iphone

我正在尝试制作一个动画并且顺时针填充黑色的圆圈,圆形动画的持续时间预定义为20秒,我想要做的是前10秒将填充黑色和圆圈的其余部分将用红色填充,并且在总共20秒后它将变成2个彩色的圆形圆圈,但我找不到它的任何程序,这里是我绘制圆形动画的代码:

-(void)makeCircle{
int radius = 100;
CAShapeLayer *circle = [CAShapeLayer layer];
//make a circular shape
circle.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 2.0*radius, 2.0*radius)cornerRadius:radius].CGPath;
//centre the shape in self.view
circle.position = CGPointMake(CGRectGetMidX(self.view.frame)-radius, CGRectGetMidY(self.view.frame)-radius);
//configure the appearence of the circle
circle.fillColor = [UIColor clearColor].CGColor;

circle.strokeColor =[UIColor blackColor].CGColor;
circle.lineWidth = 5;

//add to parent layer
[self.view.layer addSublayer:circle];

//configure animation
CABasicAnimation *drawAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
drawAnimation.duration = 20.0;//animate over 10 seconds or so...
drawAnimation.repeatCount=1.0;//animate only once;

drawAnimation.removedOnCompletion=NO;

drawAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
drawAnimation.toValue = [NSNumber numberWithFloat:1.0f];

drawAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
[circle addAnimation:drawAnimation forKey:@"drawCircleAnimation"];
}

但我需要知道我该怎么做?

1 个答案:

答案 0 :(得分:0)

你看过This?

吗?

我认为这可能有所帮助。