Reputation: 912
I'm trying to figure out the best way to do hit detection on a CALayer containing a non-rectangular path. I am aware of the CGContextPathContainsPoint
function but im not sure how to get a reference to the appropriate CGContextRef
when I need to do hit detection (like mouse down). Is it safe to retain a reference to the CGContextRef
that is passed to the (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx
delegate method for purposes of hit detection? I'm not sure if the same CGContextRef
could potentially be modified by other layers.
Upvotes: 0
Views: 993
Reputation: 1118
Use CAShapeLayer
instead CALayer
, if you are dealing with drawing shapes over layer.
CAShapeLayer
contains CGPath, so you don't need to maintain CGPath in your CALayer
.
Upvotes: 1
Reputation: 96323
Have the layer own a CGPath and hit-test that. Then you don't have to worry about whether it's safe to retain the context, and you don't have to re-plot the path every time, either.
Upvotes: 3