cannyboy
cannyboy

Reputation: 24426

How to get a item's coordinates while it is animating?

I can animate something across the screen like so:

aView.frame = CGRectMake(100,100,50,50); 
[UIView animateWithDuration:25.0 delay:0.0 options:UIViewAnimationCurveLinear animations:
     ^{ 
         aView.frame = CGRectMake(200,100,50,50);         
     } 
         completion:^(BOOL finished)
     {
         aView.hidden = YES; 
     }
 ];

..but how do I get the position of the item while it is animating? If I put a button on the screen and use this action

-(IBAction)buttonTapped:(id)sender
{
   NSLog(@"x pos:%f", aframe.origin.x)l
}

then all I get from this is

x pos:200.00

..which is the final position of the item, but not the current. How do I get the current?

Upvotes: 2

Views: 433

Answers (1)

Deepak Danduprolu
Deepak Danduprolu

Reputation: 44633

Look at CALayer's presentationLayer property. It holds the current values of the layer being animated.

You will have to import QuartzCore framework.

EDIT

Specifically:

#import <QuartzCore/CALayer.h>
// ...
CGPoint inMotionPosition = myView.layer.presentationLayer.position;

Upvotes: 1

Related Questions