UIWebView 通过触摸定位文本
想要捕获 UIWebView 上的触摸,将其映射到相关的 HTML 文本,并在此时将超链接插入到 HTML 中。
找到了一个非常好的参考来干净地捕获 UIWebView 上的触摸:
我已经实现了并且效果很好。
还在 UIWebView 中找到了一个非常好的搜索和突出显示文本的参考:
http://www.icab.de/blog/2010/01/12/search-and-highlight-text-in-uiwebview/
我已经实现了它[对于搜索功能]并且效果非常好。
但我无法完全从触摸位置(而不是文本搜索)智能跳转到 UIWebView 中的特定单词。显然这是可以做到的,因为触摸并按住 UIWebView 会触发“复制或定义”弹出窗口,它显然知道您指向的特定单词。
JavaScript 从 DOM 解码的各个文本节点没有 offsetLeft 或 offsetTop 或 offsetWidth 或 offsetHeight;我知道这些需要从父节点派生。
但各个文本节点可以包含多行文本,具体取决于 HTML 源的外观。单个文本节点可能可以包含一整段文本,而这几乎不是我想要发现的一个单词。
谁能建议“复制或定义”如何如此聪明?谢谢。
Would like to capture a touch on a UIWebView, map that to the relevant HTML text and insert a hyperlink into the HTML at that point.
Found a very nice reference to cleanly capture touches on UIWebView at:
http://mithin.in/2009/08/26/detecting-taps-and-events-on-uiwebview-the-right-way/
I've implemented it and it works very well.
Also found a very nice reference to search and highlight text in a UIWebView at:
http://www.icab.de/blog/2010/01/12/search-and-highlight-text-in-uiwebview/
I've implemented it [for a search feature] and it works very well.
But I can't quite make the intellectual jump from touch position [not text search] to a specific word in the UIWebView. Obviously this can be done, since touch-and-hold on a UIWebView triggers a "Copy or Define" popup which obviously knows the specific word you've pointed at.
The individual text nodes that JavaScript decodes from the DOM have no offsetLeft or offsetTop or offsetWidth or offsetHeight; I understand these need to be derived from the parent node.
But the individual text nodes can consist of many lines of text, depending on what the HTML source looks like. Potentially a single text node can contain an entire paragraph of text, hardly the one word that I'm trying to spot.
Can anyone suggest how "Copy or Define" can be so clever? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论