相关疑难解决方法(0)

通过填充 UIImageView 层边框宽度的颜色动画进度

我有 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];
Run Code Online (Sandbox Code Playgroud)

但是它在错误的位置显示圆圈并且这个aproch没有进度,它是静态的有没有办法根据进度填充UIImageView层的边框宽度?

objective-c uiimageview cabasicanimation ios

3
推荐指数
1
解决办法
2867
查看次数

标签 统计

cabasicanimation ×1

ios ×1

objective-c ×1

uiimageview ×1