Nic*_*ard 12 core-animation objective-c cashapelayer ios uibezierpath
我想画一个用来表示进展的圆圈.进度更新可能会很快进行,我想对圆圈的更改进行动画处理.
我已尝试使用以下方法执行此操作,但似乎没有任何工作.这可能吗?
- (id)initWithFrame:(CGRect)frame strokeWidth:(CGFloat)strokeWidth insets:(UIEdgeInsets)insets
{
if (self = [super initWithFrame:frame])
{
self.strokeWidth = strokeWidth;
CGPoint arcCenter = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
CGFloat radius = CGRectGetMidX(self.bounds) - insets.top - insets.bottom;
self.circlePath = [UIBezierPath bezierPathWithArcCenter:arcCenter
radius:radius
startAngle:M_PI
endAngle:-M_PI
clockwise:YES];
[self addLayer];
}
return self;
}
- (void)setProgress:(double)progress {
_progress = progress;
[self updateAnimations];
}
- (void)addLayer {
CAShapeLayer *progressLayer = [CAShapeLayer layer];
progressLayer.path = self.circlePath.CGPath;
progressLayer.strokeColor = [[UIColor whiteColor] CGColor];
progressLayer.fillColor = [[UIColor clearColor] CGColor];
progressLayer.lineWidth = self.strokeWidth;
progressLayer.strokeStart = 10.0f;
progressLayer.strokeEnd = 40.0f;
[self.layer addSublayer:progressLayer];
self.currentProgressLayer = progressLayer;
}
- (void)updateAnimations{
self.currentProgressLayer.strokeEnd = self.progress;
[self.currentProgressLayer didChangeValueForKey:@"endValue"];
}
Run Code Online (Sandbox Code Playgroud)
目前,该代码甚至不画了圈,但在取出progressLayer的strokeStart并且strokeEnd将绘制完整的圆.
如何让它从某个点开始并根据我设置我的progress属性开始绘制圆圈?
我想到了.该strokeStart和strokeEnd值从0.0到1.0,所以我给它的值是太高.
所以,我刚刚将我的设置更新为:
- (void)setProgress:(double)progress {
_progress = progress * 0.00460;
[self updateAnimations];
}
Run Code Online (Sandbox Code Playgroud)