问题描述
我在我的应用程序中使用一个圆圈 (UIBezierPath) 作为迷你进度条。我遇到的一个问题是我只能在一个方向上为圆圈设置一次动画。假设我将圆圈绘制到 80% 并且我想将其缩小到 60%,整个圆圈被重新绘制,这不是我想要的。
使用进度条时,如果减少当前显示的百分比,则不会重绘整个进度条,进度条的大小只会从当前位置缩小到新百分比,这就是我想要的圆形图层。
这是我的圈子初始设置代码:
CAShapeLayer *greenPlayButtonCircle;
greenPlayButtonCircle = [CAShapeLayer layer];
[greenPlayButtonCircle setPath:[UIBezierPath bezierPathWithArcCenter:CGPointMake(boxView.bounds.origin.x,boxView.bounds.origin.y) radius:(boxView.frame.size.width / 2) startAngle:DEGREES_TO_RADIANS(-90) endAngle:DEGREES_TO_RADIANS(270) clockwise:YES].CGPath];
[greenPlayButtonCircle setFillColor:[UIColor clearColor].CGColor];
[greenPlayButtonCircle setStrokeColor:[UIColor greenColor].CGColor];
[greenPlayButtonCircle setLineWidth:6.0];
[greenPlayButtonCircle setPosition:boxView.center];
[greenPlayButtonCircle setAnchorPoint:CGPointMake(0.5,0.5)];
[self.view.layer addSublayer:greenPlayButtonCircle];
这是我用来尝试减少圆圈百分比(绘制部分)的代码:
[greenPlayButtonCircle setPath:[UIBezierPath bezierPathWithArcCenter:CGPointMake(boxView.bounds.origin.x,boxView.bounds.origin.y) radius:(boxView.frame.size.width / 2) startAngle:DEGREES_TO_RADIANS(-90) endAngle:DEGREES_TO_RADIANS(270) clockwise:YES].CGPath];
// Setup the circle animation.
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
[animation setDuration:0.5];
[animation setRemovedOnCompletion:YES];
[animation setFromValue:@(0)];
[animation setToValue:@(1)];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
[animation setFillMode:kCAFillModeBoth];
// Begin the circle animation.
[greenPlayButtonCircle addAnimation:animation forKey:@"drawCircleAnimation"];
这是圆圈最初的样子(设置为 100% - 这是我想要的):
现在我想减少圆圈的百分比或大小,这就是我想要的动画效果:
这就是实际发生的事情(整个圆圈被重新绘制,这不是我想要的):
有什么办法可以执行反向动画吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)