【问题标题】:How to found the intersection of two CAShapelayer如何找到两个 CAShapelayer 的交集
【发布时间】:2026-01-19 18:25:01
【问题描述】:

我有不止一个CAShapeLayer。 在拖动两层的时候,我需要看看它是否相交。

但我尝试了计算框架交点和点交点的方式。但它总是以CGRectMake(0,0,0,0) 的形式返回帧,我的意思是所有层帧为零,位置也为零。

如果有人知道,请给出一些想法。

【问题讨论】:

  • 你试过 CGRectIntersection() 了吗?
  • 您要检查layerspaths中的layers是否相交?
  • 图层是否有共同的超级图层?
  • 如果您对帧进行自定义计算,建议您调用CGRectStandardize。他们可能有奇怪的定义。
  • 显示你的代码并描述什么不适合你。

标签: ios calayer cashapelayer


【解决方案1】:

试试

if (CGRectIntersectsRect(layer1.frame, layer2.frame))
{
   /* Do something when the intersect.
}

感谢您可能想知道路径是否相交,这是一个更困难的计算 here

【讨论】:

    最近更新 更多