我有一个应用程序,我将内容加载到一个UIWebView并呈现此.我无法完全禁用用户交互,因为我希望用户能够单击链接.我只需要禁用用户选择.我发现你可以使用的互联网中的某个地方:
document.body.style.webkitUserSelect='none';
Run Code Online (Sandbox Code Playgroud)
我试着插入这个
[self.contentView stringByEvaluatingJavaScriptFromString:@"document.body.style.webkitUserSelect='none';"];
Run Code Online (Sandbox Code Playgroud)
在 webViewDidFinishLoad:
但是,它不起作用.我仍然可以在WebView中选择和复制文本.
什么想法可能会出错?
更新:这似乎只从iOS 4.3开始
我已经测试了几种解决方法,用css禁用恼人的放大镜,但是在我的iOS9流星线上构建它会出现一段时间并在几毫秒之后淡出.
它正在iOS 8上运行,但现在没有在iOS 9上使用这个css代码:
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-tap-highlight-color: rgba(0, 0, 0, 0);
-webkit-touch-callout: none;
-webkit-user-select: none;
-moz-user-select: none; /* Firefox all */
-ms-user-select: none; /* IE 10+ */
user-select: none;
-webkit-user-drag: none;
-webkit-user-modify: none;
}
Run Code Online (Sandbox Code Playgroud)
我错过了iOS 9的东西?