好的,情景很简单:
我知道我必须继承WebView,但是我必须覆盖哪些特定方法?
有什么想法吗? (欢迎任何其他方法!)
答案 0 :(得分:4)
将以下CSS添加到某个文件
html {
-ms-touch-action: manipulation;
touch-action: manipulation;
}
body {
-webkit-user-select: none !important;
-webkit-tap-highlight-color: rgba(0,0,0,0) !important;
-webkit-touch-callout: none !important;
}
将CSS链接到您的HTML
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="LayoutTemplates/css/style.css" type="text/css" />
</head>
</html>
或以编程方式禁用它
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitUserSelect='none';"];
[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitTouchCallout='none';"];
}
答案 1 :(得分:3)
好的,这是解决方案。
首先,设置Webview的编辑代表:
[_myWebview setEditingDelegate:self];
然后实现我们需要的一个功能,以拦截复制/剪切操作(或任何针对该问题的操作,但这是我们将要做的事情):
- (BOOL)webView:(WebView *)webView doCommandBySelector:(SEL)command
{
NSString* commandStr = NSStringFromSelector(command);
if ( ([commandStr isEqualToString:@"copy:"]) ||
([commandStr isEqualToString:@"cut:"]))
{
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
[pasteboard clearContents];
return YES; // YES as in "Yes, I've handled the command,
// = don't do anything else" :-)
}
else return NO;
}
我希望你不会浪费尽可能多的时间来寻找有效的答案......: - )