开发者

Trying to detect collision between animating UIImageViews

开发者 https://www.devze.com 2023-01-07 00:39 出处:网络
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 (myObj

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");
}
0

精彩评论

暂无评论...
验证码 换一张
取 消