Disable Scroll on a UIWebView allowed?

后端 未结 18 1458
深忆病人
深忆病人 2020-12-07 11:52

I have to show a web article with a UITableView under the article.

The only option I found was to display the article in a UIWebView in the

相关标签:
18条回答
  • 2020-12-07 12:30

    Starting with iOS5 we have direct access to the scrollview of the UIWebView.
    You can disable scrolling and bounces like this:

    webView.scrollView.scrollEnabled = NO; 
    webView.scrollView.bounces = NO;
    
    0 讨论(0)
  • 2020-12-07 12:30

    I think the Javascript

    <script type="text/javascript">
    touchMove = function(event) {
    event.preventDefault();
    }
    

    is far the best solution.

    Indeed :

    Your first examle, or the

    [[[WebView subviews] lastObject] setScrollingEnabled:NO];
    

    one (same things) could be rejected because not documented, or make you app crash in a further ios update.

    And the

    [[myWebView scrollView] setBounces:NO];
    

    method won't work with iOS < 5.

    0 讨论(0)
  • 2020-12-07 12:30

    I don't think the first option is forbidden by Apple.

    You could try

    [[[Webview subviews] lastObject] setScrollingEnabled:NO];
    

    If you don't want any links to work in your UIWebView, you can also do

    [myWebView setUserInteractionEnabled:NO];
    
    0 讨论(0)
  • 2020-12-07 12:38

    SWIFT 3 version

        webView.scrollView.bounces = false
        webView.scrollView.isScrollEnabled = false
    
    0 讨论(0)
  • 2020-12-07 12:38

    I placed some UIWebViews inside a UIScrollView and it wasn't scrolling for me, unless I disable the user interaction on the webviews (even with the [[webview scrollview] setScrollEnabled:NO]). So I placed the UIWebViews inside a UIView and that worked for me but then the interactive links or divs in my HTML inside the UIWebView were not working anymore.

    The only thing that worked for me is to keep the UIWebView inside the UIScrollView so the HTML interactions work but the UIScrolling does not.

    I then created a custom delegate for the webviews to listen for window.open("http:/customEvent") that is called from the HTML contained in the webview. I also added a JavaScript swipe detection that will fire up my custom event.

    When the webview delegate receives this, I pass a notification to a controller which then dynamically scrolls my UIScrollView. Obviously I had to build a logic to monitor and scroll to the next or previous page. Not the prettiest solution but It's working for me.

    0 讨论(0)
  • 2020-12-07 12:41

    Use this one <body ontouchmove="event.preventDefault()">

    0 讨论(0)
提交回复
热议问题