How to disable long touch in UIWebView?

后端 未结 4 480
南旧
南旧 2020-12-14 01:36

I want to disable long-touch from the application. I have no control on the HTML that I am loading on my WebView.

相关标签:
4条回答
  • 2020-12-14 02:13

    You could try to override the following methods from the view controller :

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
    

    this way you can replace the usual touches management with your own implementation.

    0 讨论(0)
  • 2020-12-14 02:16

    The UIWebView is no longer supported. So, you should implement WKWebView and there is a property called allowsLinkPreview with that you can enable or disable the long touch previews.

     webView.allowsLinkPreview = false
    
    0 讨论(0)
  • 2020-12-14 02:19

    Open your view in Interface Builder, click on the web view and then un-check the "User Interaction Enabled" checkbox in the attributes inspector.

    If you want to do it in code, set the web view's userInteractionEnabled property to NO.

    0 讨论(0)
  • 2020-12-14 02:38

    In webViewDidFinishLoad delegate I run a javascript on the loaded html page that disable the long touch.

    [webView stringByEvaluatingJavaScriptFromString:@"document.body.style.webkitTouchCallout='none'; document.body.style.KhtmlUserSelect='none'"];
    
    0 讨论(0)
提交回复
热议问题