Handling touches inside UIWebview

前端 未结 10 2082
感情败类
感情败类 2020-11-30 22:46

I have created a subclass of UIWebView , and have implemented the touchesBegan, touchesMoved and touchesEnded methods.

10条回答
  •  渐次进展
    2020-11-30 23:27

    If you want to detect your own taps but disable the UIWebView's taps then you can use my solution:

    -(void)recursivelyDisableTapsOnView:(UIView*)v{
        for(UIView* view in v.subviews){
            for(UIGestureRecognizer* g in view.gestureRecognizers){
                if(g == self.ownTapRecognizer){
                    continue;
                }
                if([g isKindOfClass:[UITapGestureRecognizer class]] ||
                   [g isKindOfClass:[UILongPressGestureRecognizer class]] ||
                   [g isKindOfClass:NSClassFromString(@"UITapAndAHalfRecognizer")]){
                    g.enabled = NO;
                }
            }
            [self recursivelyDisableTapsOnView:view];
        }
    }
    
    
    - (void)webViewDidFinishLoad:(UIWebView *)webView{
        [self recursivelyDisableTapsOnView:webView];
    
        //disable selection
        [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitUserSelect='none';"];
        // Disable callout
        [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitTouchCallout='none';"];
    }
    

提交回复
热议问题