Alex Rivera | Logout

How to figure out if two CGRect intersect?

Asked 2010-04-26T14:10:42.720
33

In -drawRect: I want to check if the provided rect intersects with anotherRect.

I'm not good at this geometry math stuff and especially at english so what I want to say is:

If you have two sheets of paper on the desk, and one of them covers the other either completely or just a small portion, it is rectsIntersect = YES.

How to check that out for rect and anotherRect?

Edit
Report

1 Answer

1

Try to use this.. While animating imageview you can get its actual frame by this:

[[obstacle1.layer presentationLayer] frame];

So, it will easily to make collision of two imageview

if (CGRectIntersectsRect([[obstacle1.layer presentationLayer] frame], [[bgImageView.layer
    presentationLayer] frame])) 
{

    NSLog(@"Collision 1");

}
answered 2013-03-07T09:25:30.310

Your Answer