UIWebView - How to Disable Action Sheets (UIActionSheet)?

前端 未结 5 1755
生来不讨喜
生来不讨喜 2021-02-02 04:01

I would like to know how you can disable UIActionSheets, specifically the Action Sheets being displayed after tapping and holding hyperlinks in a UIWebView. These seem to be ena

相关标签:
5条回答
  • 2021-02-02 04:33

    The dataDetectorTypes property might be what you are looking for. If you want to disable that action sheet possibility, just insert the code:

    webView.dataDetectorTypes = UIDataDetectorTypeNone;
    
    0 讨论(0)
  • 2021-02-02 04:36

    I just found this solution myself. Add this to your CSS:

    body {
      -webkit-touch-callout: none;
    }
    

    To be clear, this disables the action sheet that appears when you hold down a hyperlink.

    0 讨论(0)
  • 2021-02-02 04:43

    You can override presentViewController in UINavigationController and do nothing like this.

    @implementation CDVInAppBrowserNavigationController : UINavigationController
    
    - (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^ __nullable)(void))completion NS_AVAILABLE_IOS(5_0){
        //Do nothing.
    }
    
    @end
    
    0 讨论(0)
  • 2021-02-02 04:45
     - (void)webViewDidFinishLoad:(UIWebView *)webView
     {
        [webView stringByEvaluatingJavaScriptFromString:@"document.body.style.webkitTouchCallout='none'; document.body.style.KhtmlUserSelect='none'"];
     }
    
    0 讨论(0)
  • 2021-02-02 04:47

    You can also handle this via JavaScript by calling:

    document.documentElement.style.webkitTouchCallout = "none";
    
    0 讨论(0)
提交回复
热议问题