Trying to detect collision between animating UIImageViews
I am very new to cocoa . Well I have multiple UIImageView (animationView)flying around the screen. I am usi开发者_开发技巧ng 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");
}
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");
}
精彩评论