ios - 根据值(360)或百分比(100%)创建彩色圆圈
问题描述
此代码创建一个完整的圆圈,但我想根据 360 或 100% 的值创建一个圆圈。如果百分比是 56% 我想要 56% 圈。像这样基于百分比/值,我想要圆圈。
CAShapeLayer *circle = [CAShapeLayer layer];
circle.path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(29, 29) 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:kCAMediaTimingFunctionLinear];
[circle addAnimation:animation forKey:@"drawCircleAnimation"];
[_colouredCircle.layer.sublayers makeObjectsPerformSelector:@selector(removeFromSuperlayer)];
[_colouredCircle.layer addSublayer:circle];
解决方案
这意味着您toValue
应该匹配您的百分比。
在您的情况下,将在圆(范围)animation.toValue = @(0.56);
的 56% 处结束笔画。0...1
有关在完成后保留最终动画值的信息,请参阅此答案。
TLDR:您还必须更新模型层。
circle.strokeStart = 0;
circle.strokeEnd = 0.56; // Your target value
...
// Your animation
推荐阅读
- c++ - 运行最小 GTest 示例的链接错误
- php - Laravel with() 慢
- r - 使用多列名称的字符向量以编程方式对 data.table 进行排序
- java - 快速排序实现中的 Stackoverflow 错误
- javascript - 如何使用 Closure Compiler 在函数中定义“this”的类型
- c# - 为什么当我碰到鼠标滚轮时我的 WPF 应用程序会崩溃?
- c# - DocuSign 服务集成真实帐户无法进行身份验证
- javascript - 在递归函数调用中递增计数器
- javascript - 用作 GET 请求时准确发送的 javascript POST 请求是什么?
- php - 使用 PHP 显示数据库中的图像