layer hit test only returning layer when bottom half of layer is touched

后端 未结 8 2152
闹比i
闹比i 2021-02-10 19:14

I have a sublayer on a layer-backed view. The sublayer\'s contents are set to an Image Ref and is a 25x25 rect.
I perform a hit test on the super layer when the touchesBega

8条回答
  •  我在风中等你
    2021-02-10 19:41

    The documentation for hitTest says:

    /* Returns the farthest descendant of the layer containing point 'p'.
     * Siblings are searched in top-to-bottom order. 'p' is in the
     * coordinate system of the receiver's superlayer. */
    

    So you need to do (something like this):

    CGPoint thePoint = [touch locationInView:self];
    thePoint = [self.layer convertPoint:thePoint toLayer:self.layer.superlayer];
    CALayer *theLayer = [self.layer hitTest:thePoint];
    

    (Repeating answer from other post for completeness' sake)

提交回复
热议问题