如何在WKWebView中完全禁用滚动? [英] How to disable scrolling entirely in a WKWebView?

查看:2300
本文介绍了如何在WKWebView中完全禁用滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这看起来像一个简单的问题,可以简单地说:

I know this looks like a simple question one can simply say:

webview.scrollView.scrollEnabled = NO;
webview.scrollView.panGestureRecognizer.enabled = NO;
webview.scrollView.bounces = NO;

甚至

for (UIView* subview in webview.subviews) {
  if ([subview respondsToSelector:@selector(setScrollEnabled:)]) {
      [(id)subview setScrollEnabled:enabled];
  }

  if ([subview respondsToSelector:@selector(panGestureRecognizer)]) {
      [[(id)subview panGestureRecognizer] setEnabled:enabled];
  }
}

但它确实可以防止骂人(在 contentOffset 含义)在 WKWebview 里面阻止它接收涉及滚动的平移手势事件。

but while it does prevent scolling (in the contentOffset meaning) inside the WKWebviewit doesn't prevent it from receiving pan gesture events involving scrolling.

所以像Huffington Post这样的文章,当用户向左或向右滚动时,包含javascript以自动更改文章仍然会得到这种行为。

So articles like those of the Huffington Post, which have javascript included to automatically change articles when the user scrolls left or right still get that behavior.

如何防止这种情况?

推荐答案

您可以在其隐式scrollView上禁用滚动

You can simply disable scroll on its implicit scrollView

webView.scrollView.scrollEnabled = false

它有效。瞧...

这篇关于如何在WKWebView中完全禁用滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆