【问题标题】:is there MouseChildren for CALayer hit test?是否有用于 CALayer 命中测试的 MouseChildren?
【发布时间】:2011-03-16 13:04:57
【问题描述】:

嘿。 我有一个包含 4 个圆圈层的主层,每个圆圈内都有一个文本层:

主层 -> (4)圆形层 -> (1)textLayer.

我正在主图层上执行命中测试,我想接收被点击的圆圈。 它工作正常,但是当我点击文本区域时,我会返回文本层而不是圆形层。

在 AS3 中你有

 MouseChildren = true/false.

如何在目标 c 中获得此功能?

谢谢

沙尼

【问题讨论】:

    标签: iphone ios ipad calayer hittest


    【解决方案1】:

    只需使用superlayer 属性,如下所示:

    if([theLayer isKindOfClass:[CATextLayer class]])
        theLayer = theLayer.superlayer;
    

    换句话说,如果你已经有了圆圈层,theLayer 不会改变;如果它是文本子图层之一,theLayer 将更改为指向包含该子图层的图层。

    【讨论】:

      猜你喜欢
      • 2011-02-26
      • 1970-01-01
      • 2011-09-04
      • 2021-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多