我正在尝试找出如何判断我的 2 个圆形框架是否相互交叉。因为它们是圆形的,所以我不能使用 cgrectintersectsrect 并且我不确定如何去做。是否有 cgframeintersectsframe 或类似的东西?
我做了一轮 uiimageviews
circle1 = [[uiimageview alloc] initwithframe:cgrectmake (100,100,50,50);
circle1.layer.cornerradius = 25;
circle1.clipstobounds = yes;
[self.view addsubview:circle1];
除了 x 和 y 原点不同外,另一个圆基本上也是这样 我也已经进口quartzcore
最佳答案
只需计算圆心之间的距离并检查它是否小于半径:
float distanceBetweenCenters = sqrt(pow(circle1.center.x - circle2.center.x, 2) +
pow(circle1.center.y - circle2.center.y, 2));
BOOL isIntersecting = distanceBetweenCenters <= 2 * radius;
这将告诉您圆是否相交或相互接触。替换 <=
与 <
排除“触摸”。
关于ios - 圆框相交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23187386/