当我点击时,我想增加一个计数器来增加圆的弧度。
该线应该动画到下一个尺寸并保持在那里直到下一个增量(让我们说从水龙头 - 我已经在其他地方测量过),然后动画到下一个尺寸等。
见下面的例子
这是我到目前为止找到的一些代码......
_radius = 150;
CAShapeLayer *circle = [CAShapeLayer layer]; // Make a circular shape circle.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 2.0*_radius, 2.0*_radius) cornerRadius:_radius].CGPath; // Center the shape in self.view circle.position = CGPointMake(CGRectGetMidX(self.target.frame)-_radius, CGRectGetMidY(self.target.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 = 0.3; // "animate over 10 seconds or so.." drawAnimation.repeatCount = 1.0; // Animate only once.. drawAnimation.removedOnCompletion = NO; // Remain stroked after the animation.. // Animate from no part of the stroke being drawn to the entire stroke being drawn drawAnimation.fromValue = [NSNumber numberWithFloat:0.0f]; //drawAnimation.toValue = [NSNumber numberWithFloat:0.0f]; // Experiment with timing to get the appearence to look the way you want drawAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]; // Add the animation to the circle [circle addAnimation:drawAnimation forKey:@"drawCircleAnimation"];