设置剪辑UIImage的UIBezierPath的动画

koh*_*Xun 7 core-animation clipping uiimage ios uibezierpath

我有一个看起来像甜甜圈的图像,并希望对其进行动画处理,使其看起来像圆环未完成(笔划未关闭).很难描述,但想象一下速度表达到100并且你驱动50.我已经在UIGraphicsBeginImageContextWithOptions内的路径和[path addClip]的帮助下完成了屏蔽,其中我也渲染了UIImage.

我现在的问题是,我可以或如何设置路径的动画.我尝试使用CABasicAnimation和2个路径(第一个路径,其中startAngle和endAngle是相同的,第二个路径是endAngle是所需的角度),"path"作为keyPath但是不起作用.

任何帮助;)

Rob*_*Rob 3

UIBezierPath使用动画制作CABasicAnimation使用...

UIBezierPath *bezierPath = [self bezierPath];

CAShapeLayer *bezierLayer = [[CAShapeLayer alloc] init];

bezierLayer.path = bezierPath.CGPath;
bezierLayer.strokeColor = [UIColor redColor].CGColor;
bezierLayer.fillColor = [UIColor clearColor].CGColor;
bezierLayer.lineWidth = 5.0;
bezierLayer.strokeStart = 0.0;
bezierLayer.strokeEnd = 1.0;
[self.view.layer addSublayer:bezierLayer];

if (animate)
{
    CABasicAnimation *animateStrokeEnd = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
    animateStrokeEnd.duration = 1.0;
    animateStrokeEnd.fromValue = @0.0f;
    animateStrokeEnd.toValue = @1.0f;
    [bezierLayer addAnimation:animateStrokeEnd forKey:@"strokeEndAnimation"];
}
Run Code Online (Sandbox Code Playgroud)