如何禁用 UIWebView 上长按时出现的放大镜?我不想禁用用户交互,但也不想在网页视图中显示缩放镜。有什么建议吗?
如何禁用 UIWebView 上长按时出现的放大镜?我不想禁用用户交互,但也不想在网页视图中显示缩放镜。有什么建议吗?
-webkit-user-select: none
来实现)。UIWebView
内部,但请注意。)UIWebView
子视图并枚举它们的gestureRecognizers
。每当我遇到一个UILongPressGestureRecognizer
时,我将其enabled
设置为NO
。blur
事件,并在其发生时再次遍历子视图树。因为我不知道如何使用-webkit-user-select: none
,所以我寻找其他方法。然后我偶然发现了这个自定义UIWebView的上下文菜单,随后将其与-webkit-user-select: none
结合使用。
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[webView stringByEvaluatingJavaScriptFromString:@"document.body.style.webkitUserSelect='none';"];
}
-webkit-user-select: none;
无法达到效果。相反,我找到了一个非常不被文档记录的属性-webkit-touch-callout。body, body * {
-webkit-user-select: none !important;
user-select: none !important;
-webkit-user-callout: none !important;
-webkit-touch-callout: none !important;
}
input, textarea {
-webkit-user-select: text !important;
user-select: text !important;
-webkit-user-callout: default !important;
-webkit-touch-callout: default !important;
}
有人提到-webkit-user-callout
是-webkit-touch-callback
的旧版本,我仅仅是为了保险起见加上了这个。
对于我们的 Cordova & Swift 项目,我做了:
override init!(webView theWebView: UIWebView!)
{
super.init(webView: theWebView)
removeLoupe()
}
/**
Removes the magnifying glass by adding a long press gesture that overrides the inherent one that spawns
a the loupe by default.
*/
private func removeLoupe()
{
let views = webView?.subviews
if (views == nil || views?.count == 0)
{
return
}
let longPress = UILongPressGestureRecognizer(target: self, action: "handleLongPress:")
longPress.minimumPressDuration = 0.045
longPress.allowableMovement = 100.0
for view in views!
{
if (view.isKindOfClass(UIScrollView))
{
let subViews = view.subviews
let browser = subViews[0]
browser.addGestureRecognizer(longPress)
break;
}
}
}
/**
Hack to override loupe appearence in webviews.
*/
func handleLongPress(sender:UILongPressGestureRecognizer)
{
}
CDVPlugin
类(或者更确切地说是我的自定义版本)。<feature name="CustomCDVPlugin">
<param name="ios-package" value="CustomCDVPlugin" />
<param name="onload" value="true" />
</feature>
init()
方法。