CALayer hitTest with sublayers

I have a structure consisting of a root layer and 2 CALayer subclasses. These 2 layers also contain a layer.

Here's the schema:

ROOT LAYER 
    |
    |------- LAYER A
    |           |---------BG
    |
    |
    |--------LAYER B
                |---------BG

      

If I call the method hitTest

on ROOT LAYER

, it returns the innermost level in the hierarchy. So if the user clicks LAYER A

, I get BG

from LAYER A

.

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

      

How can I stop the responder chain and get directly LAYER A

or LAYER B

from the HitTest posted to ROOT LAYER

?

+3


source to share


1 answer


If these layers are your own CALayer subclasses, you can override hitTest:

or containsPoint:

to perform your own logic.

Overriding containsPoint:

and returning NO

in your background layers will stop returning them from their implementations hitTest:

.



Alternatively, you can override hitTest:

in layers A and B and revert self

if they contain point.

+5


source







All Articles