简体   繁体   中英

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.

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

UIView s 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM