Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hit testing appears to be broken #23

Open
dandan78 opened this issue Oct 16, 2012 · 4 comments
Open

hit testing appears to be broken #23

dandan78 opened this issue Oct 16, 2012 · 4 comments

Comments

@dandan78
Copy link

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.

@reklis
Copy link
Owner

reklis commented Oct 16, 2012

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

@reklis
Copy link
Owner

reklis commented Oct 16, 2012

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

@dandan78
Copy link
Author

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?

@reklis
Copy link
Owner

reklis commented Oct 17, 2012

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants