Reputation: 1
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");
}
Upvotes: 0
Views: 426
Reputation: 81868
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");
}
Upvotes: 1