【发布时间】:2012-01-29 02:16:46
【问题描述】:
我基本上需要一种以图形方式创建路径以导入我的应用程序的方法,以便我可以在 CAKeyframeAnimation 对象中将它们用作动画路径。我现在也有点缺乏时间来推出我自己的单独工具来做到这一点。所以我认为 SVGkit 可能是最快/最简单的方法。
但我现在无法正确添加构成整个路径的不同子路径。
更新:
到目前为止,我有这个:
// l has already been setup and added to the main view layer:
// it's the CALayer whose position I'm trying to animate over the path.
SVGDocument *document = [SVGDocument documentNamed:@"pathtest.svg"];
CALayer *f = [document layerTree];
CGMutablePathRef path = CGPathCreateMutable();
for(int i = 0; i < [f.sublayers count]; i++)
CGPathAddPath(path, NULL, ((CAShapeLayer*)[f.sublayers objectAtIndex:i]).path);
CAKeyframeAnimation *a = [CAKeyframeAnimation animationWithKeyPath:@"position"];
a.path = path;
a.fillMode = kCAFillModeForwards;
a.removedOnCompletion = NO;
a.duration = 5.0;
[l addAnimation:a forKey:nil];
上面的代码“几乎”正确(但不完全,有趣):构成我的路径的不同子路径被添加到主路径中。但是子路径似乎没有添加到先前子路径的末尾。也就是说,在运行动画时,CALayer 似乎平移了一段路径,然后跳转到另一个位置,从该位置开始沿着第二个子路径平滑平移,等等。对于构成主路径的所有子路径。
有什么想法吗?
【问题讨论】:
标签: ios svg core-animation core-graphics