CALayer hitTest与子层

Mat*_*oal 3 core-animation objective-c calayer hittest

我有一个在根层和2个CALayer子类组成的结构.这两层也包含一层.

这是一个方案:

ROOT LAYER 
    |
    |------- LAYER A
    |           |---------BG
    |
    |
    |--------LAYER B
                |---------BG
Run Code Online (Sandbox Code Playgroud)

如果我hitTestROOT LAYER其上调用方法,则将最内层返回到层次结构中.因此,如果用户点击了LAYER A我得到BGLAYER A.

//In this example hitResult will contains the BG of LAYER A or the BG of LAYER B
CALayer *hitResult = [rootLayer hitTest:point)]; 
Run Code Online (Sandbox Code Playgroud)

如何停止响应链并直接LAYER ALAYER B从HitTest发送到ROOT LAYER

Dav*_*ist 5

如果这些图层是您自己的CALayer子类,那么您可以覆盖hitTest:containsPoint:在那里执行您自己的逻辑.

覆盖containsPoint:并返回NO背景图层将阻止它们从超级层hitTest:实现返回.

或者,您可以hitTest:在A层和B层中覆盖,self如果它们包含该点则返回.