Mat*_*ong 10
更新:意识到有一个更好的解决方案来解决这个问题.只需创建一个圆形路径,并将CAShapeLayer的strokeEnd属性设置为0.0f到1.0f.看看Ole的回答:在iPhone上用CAKeyFrameAnimation绘制路径
原始答案:
您可以使用CAKeyframeAnimation并创建Core Graphics路径.此代码以抛物线模式激活图层,但您可以对其进行调整以绘制圆形.
- (CAAnimation*)pathAnimation;
{
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path,NULL,50.0,120.0);
CGPathAddCurveToPoint(path,NULL,50.0,275.0,
150.0,275.0,
150.0,120.0);
CGPathAddCurveToPoint(path,NULL,150.0,275.0,
250.0,275.0,
250.0,120.0);
CGPathAddCurveToPoint(path,NULL,250.0,275.0,
350.0,275.0,
350.0,120.0);
CGPathAddCurveToPoint(path,NULL,350.0,275.0,
450.0,275.0,
450.0,120.0);
CAKeyframeAnimation *
animation = [CAKeyframeAnimation
animationWithKeyPath:@"position"];
[animation setPath:path];
[animation setDuration:3.0];
[animation setAutoreverses:YES];
CFRelease(path);
return animation;
}
Run Code Online (Sandbox Code Playgroud)