Disable Scroll on a UIWebView allowed?

后端 未结 18 1457
深忆病人
深忆病人 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:25

    Try this in your HTML (<HEAD> tag)

    <script> 
      document.ontouchmove = function(event) { event.preventDefault(); }
    </script>
    

    It will disable scrolling on your web page.

    (works on any webpage, not just UIWebView)

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

    I needed to disable scrolling because dismissing a custom keyboard really messed up scrolling with the webView. Nothing else worked and I resorted to something like this:

    -(void)viewDidLoad{
      [super viewDidLoad];
      [self.webView.scrollView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil];
      self.webView.scrollView.showsVerticalScrollIndicator = NO;
    }  
    
    -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
        if (!CGPointEqualToPoint(self.webView.scrollView.contentOffset, CGPointZero)){
            self.contentOffset = CGPointZero;
        }
    }
    
    0 讨论(0)
  • 2020-12-07 12:26

    Since this question is still applicable, there is a new way to do it! (iOS 7.0+, perhaps iOS 6 also, not confirmed)

    webView.scrollView.scrollEnabled = NO;
    

    Take care :)

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

    You can simply set the web view user interaction property to no i.e.

    webView.userInteractionEnabled = NO;
    

    Its pretty simple and works fine,thanks :)

    0 讨论(0)
  • 2020-12-07 12:28
    [[[WebView subviews] lastObject] setScrollingEnabled:NO];
    
    0 讨论(0)
  • 2020-12-07 12:29

    for all ios versions you can use this code instead of setScrollEnabled :

    for (UIView *view in webview.subviews) {
        if ([view isKindOfClass:[UIScrollView class]]) {
           UIScrollView *scrollView = (UIScrollView *)view;
           scrollView.scrollEnabled = NO;
        }
    }
    
    0 讨论(0)
提交回复
热议问题