iBooks 是如何做到这一点的?
我目前正在 uiwebview 中显示文本。但是,我想允许用户选择文本并使用所选文本执行某些操作(谷歌搜索)。苹果公司已经在 iBooks 上做了类似的事情。当您单击某个单词时,您可以选择在字典中查找该单词。我怎样才能用 Webview 做同样的事情?
UIMenuController 似乎是我需要看的。但我找不到任何有关如何执行此操作的示例代码。我是 iPhone 开发新手,请帮忙。
I am currently displaying text in a uiwebview. However, I would like to allow a user to select text and perform some action with the selected text (google it). Apple has done this sort of thing with iBooks. When you click on a word you can choose to look up the word in a dictionary. How can I do the same thing with Webview?
UIMenuController seems to be what I need to look at. But I couldn't find any sample code on how to do this. I'm new to iPhone development please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从 iOS 3.2 开始,您可以使用 UIMenuController 来添加额外的 UIMenuItems 到系统菜单在 UIWebView 中选择文本时出现。这是一个简单的示例:
Apple 在 添加自定义编辑菜单项部分。
Starting in iOS 3.2 you can use UIMenuController to add additional UIMenuItems to the system menu that appears when selecting text in a UIWebView. Here's a simple example:
Apple describes how this works in the Adding Custom Edit Menu Items section of the Device Features Programming Guide.
这篇最近的博文 似乎表明,至少在 iPad iOS 分支中,某些 iBooks 功能是基于私有 API 的。
This recent blog post from a developer would seem to suggest that at least in the iPad iOS branch, some iBooks functionality is based on private APIs.