我正在尝试创建一个圆形条形图,当您执行时间间隔时,您可以在iOS上的本机摄像机中的录制按钮周围找到这样的条。
一个圆圈是沿着动画创建的,一旦它完成,就会“自然”地移除。
我尝试了下一个代码:
CAShapeLayer *circle = [CAShapeLayer layer];
circle.path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.lapseBtnOutlet.center.x, self.lapseBtnOutlet.center.y) radius:28 startAngle:2*M_PI*0-M_PI_2 endAngle:2*M_PI*1-M_PI_2 clockwise:YES].CGPath;
circle.fillColor = [UIColor clearColor].CGColor;
circle.strokeColor = [UIColor whiteColor].CGColor;
circle.lineWidth = 2.0;
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
animation.duration = self.lapseInterval;
animation.removedOnCompletion = NO;
animation.fromValue = @(0);
animation.toValue = @(1);
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
[circle addAnimation:animation forKey:@"drawCircleAnimation"];但我现在的问题是,我不知道如何“删除”线从开始到结束。
我尝试了自动反转属性,但它删除了从端到开始的循环,而不是从开始到结束。有什么想法吗?
发布于 2014-12-05 20:58:17
您需要将strokeStart从0动画变为1,当动画完成时,删除形状层。
- (void)viewDidLoad {
[super viewDidLoad];
[self performSelector:@selector(animateProperty:) withObject:@"strokeEnd" afterDelay:1];
[self performSelector:@selector(animateProperty:) withObject:@"strokeStart" afterDelay:3];
}
-(void)animateProperty:(NSString *) prop {
if (! self.circle) {
self.circle = [CAShapeLayer layer];
self.circle.path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.lapseBtnOutlet.center.x, self.lapseBtnOutlet.center.y) radius:28 startAngle:2*M_PI*0-M_PI_2 endAngle:2*M_PI*1-M_PI_2 clockwise:YES].CGPath;
self.circle.fillColor = [UIColor clearColor].CGColor;
self.circle.strokeColor = [UIColor whiteColor].CGColor;
self.circle.lineWidth = 2.0;
[self.view.layer addSublayer:self.circle];
}
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:prop];
animation.delegate = ([prop isEqualToString:@"strokeStart"])? self : nil;
animation.duration = 1;
animation.removedOnCompletion = NO;
animation.fromValue = @0;
animation.toValue = @1;
[self.circle addAnimation:animation forKey:prop];
}
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
[self.circle removeFromSuperlayer];
self.circle = nil;
}https://stackoverflow.com/questions/27323006
复制相似问题