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.
views:
195answers:
1
+2
A:
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.
Peter Hosey
2010-04-16 18:23:31