views:

506

answers:

1

Hi ,

I am using SnowFall app, in which a image is falling from top of screen to bottom. This app uses animation to achieve this task.

// put the flake in our main view [self.view addSubview:flakeView];

[UIView beginAnimations:nil context:flakeView];
// set up how fast the flake will fall
[UIView setAnimationDuration:4 * speed];

// set the postion where flake will move to
//flakeView.frame = CGRectMake(endX, 500.0, 25.0 * scale, 25.0 * scale);
flakeView.frame = CGRectMake(endX, 500.0,16, 16);

// set a stop callback so we can cleanup the flake when it reaches the
// end of its animation
[UIView setAnimationDidStopSelector:@selector(onAnimationComplete:finished:context:)];
[UIView setAnimationDelegate:self];
[UIView commitAnimations];

My Problem is I need to capture frame of image where they are moving.

Is there any way so that I can find what is the current location of image on the screen.

Thanks

EDIT: I am trying to use : CGRectIntersectsRect(frame1, frame2) where frame1 is image which is animating and frame2 is an object. If image intersect the object I have to some thing.

+1  A: 

When you apply an animation like this, the view's frame (and the frame of the view's CALayer) instantly reflect the final position.

To get the frame of the current position during an animation, you need the view's layer's presentationLayer.

CALayer *layer = flakeView.layer.presentationLayer;
CGRect layerFrame = layer.frame;
BOOL intersects = CGRectIntersectsRect(layerFrame, frame2);
iKenndac
Thanks a lot!!!But is showing an error on I line: "accessing unknown presentationLayer component of property" Here, flakeView is UIImageView, UIImageView* flakeView = [[UIImageView alloc] initWithImage:flakeImage];AndFrame to is another UIImageView as UIImageView *frame2;Do I need to write the code before sarting animation or in setAnimationDidStopSelector method.Please help me
iPhoneDev
Animations happen in between [UIView commitAnimations]; and setAnimationDidStopSelector. If you want to check the position of the layer while it's animating, you'll need to create a thread or timer or something that will check the position of the layer during the animation.
iKenndac
Thanks again :) your solution worked. howsoever my problem is still there. I am generating images in timer, so CGRectIntersectsRect(layerFrame, frame2); get confused which image to check. But thanks a lot for you ans.
iPhoneDev