views:

24

answers:

1

Hi , I am very new to cocoa . Well I have multiple UIImageView (animationView)flying around the screen. I am using UIAnimation class to animate them. While I have one more UIImageView (myObject).I m trying to collide these while i move "myObject" around the screen using touchesMoved method. The problem is I am not able to detect the collision. I m using the following method :

 if (CGRectIntersectsRect(animationView.frame, myObject.frame)) {
   NSLog(@"Collision occurred");
 }
+1  A: 

I assume you are talking about CAAnimation, not UIAnimation.

In Core Animation the current values of animated properties are not reflected in the original objects (views, layers) on which they have been applied. Instead, you have to look at a layer's presentationLayer to get the currently effective value:

CGRect viewFrame = ((CALayer*)[animationView.layer presentationLayer]).frame;
CGRect objectFrame = ((CALayer*)[myObject.layer presentationLayer]).frame;
if (CGRectIntersectsRect(viewFrame, objectFrame)) {
    NSLog(@"Collision occurred");
}
Nikolai Ruhe
Hi, yes indeed i was using UIAnimation for moving UIImageViews around the screen. I had tried using similar things but it throws me an error as request for member is not something of a structure or union.I have imported QuartzCore/QuartzCore.h and working on an iPhone app , if that helps .
Vikas
Oops, that happens when you don't test. I forgot the cast. It's necessary since `presentationLayer` returns id types. I edited the answer.
Nikolai Ruhe
Thanks Ruhe, but the problem still persists. I wonder what I am missing here.
Vikas