SVGKit
SVGKit copied to clipboard
hit testing appears to be broken
I'm trying to use SVGKit to load an .svg file with named objects in it, and then use hit testing to figure out which object the user has touched. What led me here was this blog post by adamgit and a brief discussion in the comments section.
At any rate, I tried adding a UITouchGestureRecognizer
to the sample iPad project and identifying the touched object with the following code
NSLog(@"%@,%@", NSStringFromCGPoint(location), [recognizer.view.layer hitTest:location].name);
It turns out that the accuracy of the hit testing depends on the zoom level. On my simple test file, which contains a blue rectangle and a red rectangle, it works pretty well at the default zoom level, but is still slightly off. However, zooming in/out messes things up a whole lot.
A more complex file, however, does not work accurately even at the default zoom level, but does improve as I zoom in.
I noticed that adamgit has commited a number of changes that remain to be merged with the master branch, including a modification of the hitTest:
method in CAShapeLayerWithHitTest
. Pasting the changes into the appropriate file in XCode (yeah, I'm not quite there yet with git/github), results in hit testing not working at all at any zoom level. Could be that I missed related code changes in other files.
We are in the middle of changing the hit testing, I'll add your test file to the test suite to confirm the new stuff works properly during the merge
also, be sure you are using convertPoint:toView:
and covertPoint:fromView
when passing points between views, don't know for sure if that is this issue, but you'll probably need to do it at some point.
http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html
Thanks for the feedback.
I'm not sure that's applicable in this case. The hitTest:
method of recognize.view.layer
is being called with the CGPoint
of the touch event. Since the UITouchGestureRecognizer
is associated with the view that the layer belongs to, no conversion is needed, although it should be happening at the next level, which is to say in CAShapeLayerWithHitTest
.
Do you have any idea when the hit testing rewrite will be finished?
I don't have an ETA right now, best guess is a couple of weeks. Try out @adamgit transforms branch and see if you get better results.