0

我想用 CABasicAnimation 画一个圆,但奇怪的是它在动画过程中显示了一个椭圆,代码如下:

 //---------------draw circle
// Set up the shape of the circle
int radius = 10;
CAShapeLayer *circle = [CAShapeLayer layer];
// Make a circular shape
circle.path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.frame.size.width/2 ,self.view.frame.size.height/2) radius:radius startAngle:0 endAngle:M_PI*2 clockwise:NO].CGPath;
// Configure the apperence of the circle
circle.fillColor = [UIColor redColor].CGColor;
circle.strokeColor = [UIColor redColor].CGColor;
circle.lineWidth = 1;
// Add to parent layer
[self.view.layer addSublayer:circle];
// Configure animation
CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"path"];
[pathAnimation setFromValue:(id)[UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.frame.size.width/2 ,self.view.frame.size.height/2) radius:0 startAngle:0 endAngle:M_PI*2 clockwise:NO].CGPath];
[pathAnimation setToValue:(id)[UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.frame.size.width/2 ,self.view.frame.size.height/2) radius:radius*1.2 startAngle:0 endAngle:M_PI*2 clockwise:NO].CGPath];
[pathAnimation setDuration:15.0f];
[pathAnimation setRepeatCount:1.0f];
[pathAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
circle.path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2) radius:radius startAngle:0 endAngle:M_PI*2 clockwise:NO].CGPath;
[circle addAnimation:pathAnimation forKey:@"changePathAnimation"]; 

我该如何处理。

4

1 回答 1

3

就这样试试

CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"path"];
[pathAnimation setFromValue:(id)[UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.frame.size.width/2 ,self.view.frame.size.height/2) radius:10 startAngle:0 endAngle:M_PI*2 clockwise:NO].CGPath];
[pathAnimation setToValue:(id)[UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.frame.size.width/2 ,self.view.frame.size.height/2) radius:radius*1.2 startAngle:0 endAngle:M_PI*2 clockwise:NO].CGPath];
[pathAnimation setDuration:15.0f];
[pathAnimation setRepeatCount:1.0f];
[pathAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
circle.path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2) radius:radius startAngle:0 endAngle:M_PI*2 clockwise:NO].CGPath;
[circle addAnimation:pathAnimation forKey:@"changePathAnimation"]; 
于 2013-10-18T04:33:45.283 回答