简体   繁体   English

查找两个自定义UIView之间的交集

[英]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). iPhone中是否有任何方法可以找到两个自定义UIView的交集(假设两个视图是圆形的并且在同一超级视图中)。 If there is no such method, what is the best way to achieve this goal. 如果没有这样的方法,那么实现此目标的最佳方法是什么。

You could use CGRectIntersectsRect . 您可以使用CGRectIntersectsRect

CGRectIntersectsRect CGRectIntersectsRect
Returns whether two rectangles intersect. 返回两个矩形是否相交。

bool CGRectIntersectsRect (
   CGRect rect1,
   CGRect rect2
);

Parameters 参量
rect1 rect1
The first rectangle to examine. 要检查的第一个矩形。
rect2 rect2
The second rectangle to examine. 要检查的第二个矩形。

There's an example on this question Objective-C: Issue with CGRect .frame intersect/contains 这个问题有一个例子Objective-C:CGRect问题。框架相交/包含

UIView s are all of rectangular shape. UIView都是矩形的。

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). 对于圆形,这并不复杂(取中心距离和每个半径)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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