【发布时间】:2016-06-24 10:44:37
【问题描述】:
我有 UIImageView,我已经把它做成了一个像这张图片一样宽度层的圆圈:
用户可以更新图像并上传新图像,上传图像时我有一个进度回调。我想要的是在上传图像时用颜色为边框设置动画,例如当用户点击上传时,边框从顶部开始以绿色开始并根据进度填充宽度。
我尝试使用此代码:
CAShapeLayer *circle = [CAShapeLayer layer];
circle.path = [UIBezierPath bezierPathWithArcCenter:CGPointZero radius:27 startAngle:-M_PI_2 endAngle:2 * M_PI - M_PI_2 clockwise:YES].CGPath;
circle.fillColor = [UIColor clearColor].CGColor;
circle.strokeColor = [UIColor greenColor].CGColor;
circle.lineWidth = 4;
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
animation.duration = 10;
animation.removedOnCompletion = NO;
animation.fromValue = @(0);
animation.toValue = @(1);
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[circle addAnimation:animation forKey:@"drawCircleAnimation"];
[imageView.layer.sublayers makeObjectsPerformSelector:@selector(removeFromSuperlayer)];
[imageView.layer addSublayer:circle];
但是它显示的圆圈位置错误并且这个aproch没有进度,它是静态的有没有办法根据进度填充UIImageView图层的边框宽度?
【问题讨论】:
-
感谢您的链接,但我真的很想自己实现它并使用 UIImageView 的图层并根据从 0 到 1 的进度值动画填充边框颜色
标签: ios objective-c uiimageview cabasicanimation