简体   繁体   中英

How can I match UITouch objects in Obj-C with corresponding touch objects in WebKit JavaScript?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM