Search code examples
objective-ccgpathcashapelayer

Using CGPathContainsPoint on CAShapeLayer.path After Moving the Layer


When using CGPathContainsPoint my results are consistent with the original position of the CAShapeLayer but not its current position. Is this normal, and do I need to apply the tranformation on the CGPoint I am testing, or should I be looking for a problem elsewhere in my code? My CAShapeLayer was simply moved by updating its .position property one time.

For completeness, I'm adding that my CAShapeLayer is a sublayer of a UIButton.layer.


Solution

  • To answer my own question, I needed to convert the touch point's location (which is in the UIButton's coordinate space) to the CAShapLayer's coordinate space using:

    CGPoint convertedTouchPoint = [myButton.layer convertPoint:touchPoint toLayer:myShapeLayer];