Amit Singh
Amit Singh

Reputation: 8383

Find intersection between two custom UIView

Is there any method in iPhone to find the intersection of two custom UIView (lets say two views are circular and are in same super view). If there is no such method, what is the best way to achieve this goal.

Upvotes: 1

Views: 1206

Answers (2)

Eiko
Eiko

Reputation: 25632

UIViews are all of rectangular shape.

If you need custom shapes, you need to check for yourself. With circular shapes, this is not complicated (take distance of centers and the radius of each one).

Upvotes: 2

Henrik P. Hessel
Henrik P. Hessel

Reputation: 36617

You could use CGRectIntersectsRect.

CGRectIntersectsRect
Returns whether two rectangles intersect.

bool CGRectIntersectsRect (
   CGRect rect1,
   CGRect rect2
);

Parameters
rect1
The first rectangle to examine.
rect2
The second rectangle to examine.

There's an example on this question Objective-C: Issue with CGRect .frame intersect/contains

Upvotes: 5

Related Questions