如何禁用UIWebview中的放大镜?
如何禁用在 UIWebView 上按住触摸时出现的放大镜?我不想禁用用户交互,但我不想让网络视图显示变焦玻璃。有什么想法吗?
How can I disable the magnifying glass that appears when you hold the touch on a UIWebView? I don't want to to disable user interaction but I don't want the webview to show that zoom glass. Any Ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
不,放大镜与选择有着千丝万缕的联系。要禁用它,您必须完全禁用选择(您可以使用
-webkit-user-select: none
来执行此操作)。No, the loupe is inextricably linked to selection. To disable it, you will have to disable selection entirely (you can use
-webkit-user-select: none
to do that).因为接受的解决方案对我不起作用,所以我不得不寻找其他选项,然后我找到了一个。
请注意,我不知道苹果是否批准这种技术。使用它需要您自己承担恐惧和风险。
(我们的没有被拒绝;我认为 Apple 不太关心你弄乱
UIWebView
内部结构,但请注意。)我所做的是递归地遍历
UIWebView
子视图并枚举它们的手势识别器
。每当我遇到UILongPressGestureRecognizer
,我设置了它的已启用
为否
。这完全摆脱了放大镜,并且显然禁用了任何默认的长按功能。
每当用户开始编辑文本时,iOS 似乎都会重新启用(或重新创建)这些手势识别器。
好吧,我不介意在文本字段中使用放大镜,所以我不会立即禁用它们。
相反,我等待文本元素上的
blur
事件,当它发生时,我再次遍历子视图树。就这么简单,而且有效。
Because the accepted solution did not work for me, I had to look for other options and I found one.
Note that I don't know if Apple approves this technique. Use it at your own fear and risk.
(Ours wasn't rejected; I don't think Apple cares that much about you messing with
UIWebView
internals, but be warned.)What I did was recursively walk down
UIWebView
subviews and enumerate theirgestureRecognizers
. Whenever I encounter aUILongPressGestureRecognizer
, I set itsenabled
toNO
.This gets rid of the magnifying glass altogether and obviously disables any default long-press functionality.
It seems like iOS re-enables (or re-creates) these gesture recognizers whenever user begins to edit text.
Well, I don't mind using magnifying glass in text fields so I don't disable them immediately.
Instead, I wait for
blur
event on my text elements, and when it occurs, I walk the subview tree again.Simple as that, and it works.
因为我不知道如何使用
-webkit-user-select: none
我寻找其他方法。我偶然发现了这个 自定义上下文UIWebView 的菜单,然后我将其与-webkit-user-select: none
结合起来。Because I don't know how to use
-webkit-user-select: none
I looked for other ways. And I stumble into this Customize the contextual menu of UIWebView then I combined it with-webkit-user-select: none
.我发现仅
-webkit-user-select: none;
并不能解决问题。 ,我发现了一个相当无证的属性 -webkit-touch-callout相反 通常对 Phonegap 应用程序执行的操作是这样的:
有人提到
-webkit-user-callout
是-webkit-touch-callback
的旧版本,我已将其放入万一。I have found that
-webkit-user-select: none;
alone doesn't do the trick. Instead I have found a quite undocumented property -webkit-touch-calloutWhat I usually do with Phonegap apps is this:
Somewhere it was mentioned that
-webkit-user-callout
is a legacy version of-webkit-touch-callback
, I have put this in just in case.对于我们的科尔多瓦和我所做的 Swift 项目:
请注意,这是我的 CDVPlugin 类(或者更确切地说是我的自定义版本)。
确保您的 config.xml 文件具有:
这将确保调用
init()
方法。For our Cordova & Swift project I did:
Note that this is my
CDVPlugin
class (or rather my custom version of it).Make sure your config.xml file has:
This will ensure the
init()
method is called.