我需要一些样例代码,我可以动画的曲线/弧形路径,应该画一个完整的圆圈动画?
如有任何意见,将不胜感激。
谢谢你,坐下
发布于 2009-07-28 07:06:26
UPDATE:认识到这个问题有更好的解决方案。只需创建一个循环路径,并将CAShapeLayer的CAShapeLayer属性从0.0f动画到1.0f。看看Ole:Drawing a path with CAKeyFrameAnimation on iPhone的答案
原始答案
您可以使用CAKeyframeAnimation并创建核心图形路径。这段代码以抛物线模式绘制一个图层,但你可以调整它来画一个圆圈。
- (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;
}https://stackoverflow.com/questions/1175942
复制相似问题