webView小知识点

在创建的WebView的下面,加入代码

 for (UIView *_aView in [_myWeb subviews])
    {
        if ([_aView isKindOfClass:[UIScrollView class]])
        {

            //右侧的滚动条
            [(UIScrollView *)_aView setShowsVerticalScrollIndicator:NO];


            //下侧的滚动条
            [(UIScrollView *)_aView setShowsHorizontalScrollIndicator:NO];


            //禁止上下拖动  即可以去掉webview上拉或者下拉时出现的后面的背景

            if([[_aView class] isSubclassOfClass:[UIScrollView class]]){



                ((UIScrollView *)_aView).bounces = NO;



                _myWeb.scrollView.bounces = NO;

            }

        }
    }
- (void)webViewDidFinishLoad:(nonnull UIWebView *)webView
{


   //禁止掉复制粘贴功能 
    [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitUserSelect='none';"];
    [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitTouchCallout='none';"];
}

给webView添加手势的时候会发现,手势的方法触发不了,这时需要添加如下代码:

//必须实现 否则无法触发点击事件
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{

    return YES;

}

你可能感兴趣的:(UIWebView)