I can't figure out a good way to match UITouch objects in UIKit to their corresponding touch objects in JavaScript.
For UITouch, one typically uses the value returned by hash
message to identify the UITouch instance across touch phases. In HTML / JavaScript, touch.identifier
is used and is guaranteed to be an unique number across multiple touches.
However, the numbers returned by [aUITouch hash]
and aTouch.identifier
are not related. Any ideas on how I can match touch objects received in JavaScript notifications with the UITouch objects received in Obj-C?
Thanks.
The solution I came up with was to store the UITouch objects in a dictionary using a key derived from their location. So, a touch that occurred at x 120 y 200 is stored using the key "120:200". This all happens when overriding the sendEvent method of the main window class.
I add information to these touches (in this case, the radius of the touch area) and then push them into a dictionary in the JavaScript runtime using a similar scheme. In general the positions reported by WebKit match those reported by my window class, so the JavaScript runtime is able to use the current location of the touch as a hash to lookup touch radius.