tags:

views:

273

answers:

2

I am implementing game application.In which i am using layer for animation.

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"];

Now i want to find layer position during animation?Is it possibel?please help me.

A: 

I've never tried to do this, but you should be able to (perhaps via KVO?) monitor the CALayer's frame property (or position, or bounds, or anchorPoint, depending on what you need) during the animation.

John Biesnecker
Actually, this won't work in this case. While you can observe the layer's properties, they only reflect the start or ending values for the layer, not anything in between. As I clarify in my answer, you will need to look to the presentationLayer for current values of the layer while it is animating.
Brad Larson
Ahh, I see (as I noted, I'd never tried what I was suggesting!). For what it's worth, I've up-voted your answer. It's good to know in case I need to do something like that in the future.
John Biesnecker
+2  A: 

In order to find the current position during an animation, you will need to look at the properties of the layer's presentationLayer. The properties of the layer itself will only reflect the final target value for an implicit animation, or the initial value before you applied the CABasicAnimation. The presentationLayer gives you the instantaneous value of whatever property you are animating.

For example,

CGPoint currentPosition = [[moveLayer presentationLayer] position];

will get you the current position of the layer as it is animating about your path. Unfortunately, I believe it is difficult to use key-value observing with the presentation layer, so you may need to manually poll this value if you want to track it.

Brad Larson