我正在实现游戏应用程序。我在其中使用动画层。如何在动画期间找到CAlayer的位置?
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, previousValuex, previousValue);
CGPathAddLineToPoint(path, NULL, valuex, value);
previousValue=value;
previousValuex=valuex;
CAKeyframeAnimation *animation;
animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
animation.path = path;
animation.duration =1.0;
animation.repeatCount = 0;
//animation.rotationMode = kCAAnimationRotateAutoReverse;
animation.calculationMode = kCAAnimationPaced;
// Create a new layer for the animation to run in.
CALayer *moveLayer = [imgObject layer];
[moveLayer addAnimation:animation forKey:@"position"];
现在我想在动画过程中找到图层的位置吗?是否可能?请帮助我。
实际上,在这种情况下这不起作用。虽然您可以观察图层的属性,但它们只反映图层的开始或结束值,而不是其中的任何值。正如我在我的回答中所阐明的那样,在动画时,您需要查看presentationLayer获取图层的当前值。 – 2009-12-19 18:34:22
啊,我明白了(正如我指出的,我从来没有尝试过我的建议!)。对于它的价值,我已经投票选出了你的答案。如果我需要在将来做类似的事情,很高兴知道。 – 2009-12-20 04:12:40