美文网首页
UIWebView禁止复制实现方案

UIWebView禁止复制实现方案

作者: 有毒的程序猿 | 来源:发表于2019-08-09 15:26 被阅读0次
    一、网上方案
    - (void)webViewDidFinishLoad:(UIWebView*)theWebView
    
     [self.webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitUserSelect='none';"];
     [self.webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitTouchCallout='none';"];
    
    
    • 注释: 这个方案只能去除掉单页面应用, 既js里面没有打开两个页面.而且一些特殊的手势还是会触发弹框.
    二、手势方案
    - (void)webViewDidFinishLoad:(UIWebView*)theWebView
    
     for (UIView *subView in self.webView.scrollView.subviews) {
            for (UIGestureRecognizer *gesture in subView.gestureRecognizers) {
                gesture.delegate = self;
            }
        }
    
    - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
        if ([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]] || [gestureRecognizer isKindOfClass:NSClassFromString(@"UITapAndAHalfRecognizer")]) {
            return NO;
        }
        NSLog(@"gestureRecognizerShouldBegin == %@",NSStringFromClass([gestureRecognizer class]));
        return YES;
    }
    
    • 就是禁止掉UILongPressGestureRecognizer长按手势和UITapAndAHalfRecognizer系统的这个手势, 太坑了,测试半天才找到这个凶手

    相关文章

      网友评论

          本文标题:UIWebView禁止复制实现方案

          本文链接:https://www.haomeiwen.com/subject/wcdhjctx.html