动画Piechart fillmode?

时间:2014-10-28 23:54:19

标签: ios animation core-animation quartz-core cabasicanimation

即时动画圆圈的笔触,它看起来像

dribbble.com/shots/560534-Countdown/attachments/42066?project_id=57064

我正在为背景制作一个圆圈,然后我使用相同的路径和更细的笔划到动画路径

CAShapeLayer *minutesBackground = [CAShapeLayer layer];
minutesBackground.path=[UIBezierPath bezierPathWithArcCenter:CGPointMake((screenWidth/2), (radiusMinutes+spacing)) radius:radiusMinutes startAngle:2*M_PI*0-M_PI_2 endAngle:2*M_PI*1-M_PI_2 clockwise:YES].CGPath;
minutesBackground.fillColor = clear;
minutesBackground.strokeColor = [UIColor blackColor].CGColor;
minutesBackground.lineWidth = minutesWidth+2;

minutesCircle = [CAShapeLayer layer];
minutesCircle.path=minutesBackground.path;
minutesCircle.fillColor=clear;
minutesCircle.strokeColor=[UIColor orangeColor].CGColor;
minutesCircle.lineWidth = minutesWidth;    
minutesCircle.shadowRadius = 2;
minutesCircle.shadowColor = [UIColor orangeColor].CGColor;
minutesCircle.shadowOpacity = 5;
minutesCircle.shadowOffset = CGSizeMake(0.0, 0.0);

动画是我在互联网上发现的东西:)

minutesAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
minutesAnimation.duration = work;
minutesAnimation.repeatDuration=work;
minutesAnimation.removedOnCompletion=YES;
minutesAnimation.fillMode = kCAFillModeRemoved;
minutesAnimation.fromValue=@(0);
minutesAnimation.toValue=@(1);
minutesAnimation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
[minutesCircle addAnimation:minutesAnimation forKey:@"drawCircleAnimation"];

如果我将其设置为重复一段时间,它会产生预期效果,它会绘制,最后会被删除,然后再次绘制。

然而,我有一个动画完成时弹出的按钮,按下该按钮,我禁用它并将其alpha设置为0.0以隐藏它,然后重新启动计时器。

当我重新启动计时器时,之前绘制的圆圈仍在那里。 (某些线程问题可能?)

任何帮助表示赞赏,不确定我是否分享了足够的代码..如果有更多信息可以帮助我,请告诉我:))

1 个答案:

答案 0 :(得分:1)

动画完成后,您是否试图让minutesCircle消失?

如果是这样,问题是您已使用minutesCirclestrokeStart)和0.0strokeEnd)的默认值定义了1.0minutesAnimation正在动画strokeEnd0.0更改为1.0。但是,当动画完成并被删除时(因为您已指定removedOnCompletion YESfillMode kCAFillModeRemoved),strokeEnd的{​​{1}} 1}}恢复为原始值minutesCircle(这意味着移除动画时橙色弧将保持可见)。

如果您希望动画完成后1.0不可见,请在首次创建minutesCircle时指定minutesCirclestrokeStartstrokeEnd 1}}:

0

现在,当您的动画完成并被移除时,minutesCircle.strokeStart = 0.0; minutesCircle.strokeEnd = 0.0; 的{​​{1}}将恢复为原来的值,即strokeEnd,即使橙色笔划不再可见。< / p>