我已经阅读了几种关于stackoverflow的解决方案,但这些解决方案都无法在iOS 8.1上运行。我设法从此uiwebview-with-copy-paste-when-displaying-pdf-files中禁用长按,但是我无法获得提供以下内容的弹出式窗口:网址”中的“打开”,“添加到阅读列表”和“复制”。
//NSURL *url = [NSURL URLWithString:@"http://www.google.com/somePdf.pdf"];
NSURL *url = [NSURL URLWithString:@"http://www.google.com/"];
NSURLRequest *requestURL = [NSURLRequest requestWithURL:url];
self.mainWebView.mediaPlaybackRequiresUserAction = NO;
[self.mainWebView.scrollView setBounces:NO];
self.mainWebView.allowsInlineMediaPlayback = YES;
self.mainWebView.delegate = self;
//NSString * jsCallBack = @"window.getSelection().removeAllRanges();";
//[self.mainWebView stringByEvaluatingJavaScriptFromString:jsCallBack];
[self.mainWebView setMultipleTouchEnabled:YES];
[self.mainWebView setScalesPageToFit:YES];
[self.mainWebView loadRequest:requestURL];
UILongPressGestureRecognizer* longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:nil]; // allocating the UILongPressGestureRecognizer
longPress.allowableMovement=100; // Making sure the allowable movement isn't too narrow
longPress.minimumPressDuration=0.3; // This is important - the duration must be long enough to allow taps but not longer than the period in which the scroll view opens the magnifying glass
longPress.delegate=self; // initialization stuff
longPress.delaysTouchesBegan=YES;
longPress.delaysTouchesEnded=YES;
longPress.cancelsTouchesInView=YES; // That's when we tell the gesture recognizer to block the gestures we want
[self.mainWebView addGestureRecognizer:longPress]; // Add the gesture recognizer to the view and scroll view then release
[[self.mainWebView scrollView] addGestureRecognizer:longPress];
我已经在一些随机的pdf上对其进行了测试,由于longPress手势识别器,pdf文本无法选择。但是,在普通站点上,它仍然允许复制弹出窗口。
我将尝试使用此更改的网页设置来编辑网页,但答案是3年...
也许我走错了路?我应该尝试使用WKWebView吗?
无法在您的应用程序中禁用系统的复制/粘贴弹出窗口行为,但是您可以使用直接从Web内容中禁用此选项,-webkit-user-select: none
并且您应该仅对单个元素执行此操作,而不是对整个文档执行此操作。
这就是Apple在其技术说明之一中推荐的方式:
您可以使用DOM Touch事件touchstart,touchmove,touchend和touchcancel直接处理触摸,甚至可以在iOS的Safari中检测高级手势。与模拟的鼠标事件不同,DOM Touch事件是专门为与触摸界面一起使用而设计的,因此其行为是可靠且可预期的。有关在iOS上的Safari上使用Web内容中的触摸事件的更多信息,请参阅Safari Web内容指南的“处理事件”部分,《 Safari DOM添加参考》中的Touch,TouchEvent和TouchList类,以及位于的SlideMe示例代码。 Safari开发中心。
由于在iOS上的Safari中触摸并按住将调用“剪切/复制/粘贴”对话框,因此您也可以选择使用禁用对用户界面元素(例如菜单和按钮)的选择
-webkit-user-select: none
。重要的是仅根据需要禁用每个元素的选择。永远不要全局禁用网页中的选择。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句