3

This method return true if one CGRect intersects with another. Is there any possibility or another method which return true only if one Rect1 intersects with Rect2 on more then 50% ? if less then false..

Cœur
  • 37,241
  • 25
  • 195
  • 267
Jim
  • 8,874
  • 16
  • 68
  • 125

1 Answers1

6

When you use CGRectIntersectsRect() you get a CGrect that is the intersection of both rectanlges, so based on the area of that rectangle, you can get if its more than 50%.

Something like this:

CGrect *interRect = CGRectIntersection(rect1, rect2);

if ((interRect.size. width * interRect.size.height) > (rect2.size. width * rect2.size.height*0.5) return Yes;

I multiply width* height to get the area of the rectangle.

Jim
  • 8,874
  • 16
  • 68
  • 125
Antonio MG
  • 20,382
  • 3
  • 43
  • 62