WKWebView 可水平滚动

Posted

技术标签:

【中文标题】WKWebView 可水平滚动【英文标题】:WKWebView scrollable horizontal 【发布时间】:2018-11-28 15:12:04 【问题描述】:

我正在使用 WKWebView 并且我尝试显示的页面在水平方向上非常大,并且 WKWebView 正在尝试将所有内容都放入视图中,并且看起来确实缩小了。有没有办法让 WKWebView 可滚动而不是缩小?它可以垂直滚动,但不能水平滚动。

//Create a new Web View
webView = WKWebView()

//Assign the Web View Delegate to self
webView.navigationDelegate = self

//Define and populate the URL for the Web View
let url = URL (string: "http://www.example.com");

//Load the URL into the Web View
webView.load(URLRequest(url: url!))

//Assign the Web View as the View
view = webView

这是结果

有什么方法可以解决这个问题?

【问题讨论】:

也许this 可以帮助你。你可以试试meta.setAttribute('content', 'width=theTotalWidthOfYourPageOrAnArbitraryBigNumber'); 【参考方案1】:

我可以通过在我的 html 中添加以下内容来解决这个问题:

<meta name="viewport" content="initial-scale=1.0" />

【讨论】:

以上是关于WKWebView 可水平滚动的主要内容,如果未能解决你的问题,请参考以下文章