我想在iOS中划出一道流畅的动画使用CAPropertyAnimations

问题描述:

I want it shows animation like this我想在iOS中划出一道流畅的动画使用CAPropertyAnimations

it works like this

我要显示一个圆圈的动画。它逐渐变大。我不想改变它的位置。

我的代码如下,而且圈的位置也移动了,怎么处理呢。

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
int radius = 20; 
CGPoint drawPoint = CGPointMake(self.view.frame.size.width/2 -radius,self.view.frame.size.height/2+radius*2); 
CAShapeLayer *circle = [CAShapeLayer layer]; 
// Make a circular shape 
circle.path = [UIBezierPath bezierPathWithArcCenter:drawPoint radius:radius startAngle:0 endAngle:M_PI*2 clockwise:NO].CGPath; 
// Configure the apperence of the circle 
UIColor *pointColor =[UIColor alloc]; 
pointColor = [UIColor redColor]; 
circle.fillColor = pointColor.CGColor; 
circle.strokeColor = pointColor.CGColor; 
circle.lineWidth = 1; 
// Add to parent layer 
[self.view.layer addSublayer:circle]; 
// Configure animation 
CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; 
// Set the initial and the final values 
[pathAnimation setFromValue:[NSNumber numberWithFloat:0.5f]]; 
[pathAnimation setToValue:[NSNumber numberWithFloat:1.5f]]; 
[pathAnimation setDuration:1.0f]; 
[pathAnimation setRepeatCount:1.0f]; 
[pathAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; 
[circle addAnimation:pathAnimation forKey:@"changePathAnimation"]; //--draw circle 

}

+0

这并不相关,但你为什么在这里分配的颜色对象??? – Tarun

你的动画是相对于你的CAShapeLayer,它是(0,0)在屏幕坐标的注册点。

试试这个:

circle.path = [UIBezierPath bezierPathWithArcCenter:CGPointZero radius:radius startAngle:0 endAngle:M_PI*2 clockwise:NO].CGPath; 
circle.position = drawPoint; 
+0

非常感谢你,最后它的工作。 – bohan