Using CGPathContainsPoint on CAShapeLayer.path After Moving the Layer
-
28-06-2021 - |
Question
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];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow