gpt4 book ai didi

ios - 在 webViewDidFinishLoad 上,我在 swift3 中获得了额外的内容高度

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:30:20 25 4
gpt4 key购买 nike

  EventWebView.frame.size = EventWebView.sizeThatFits(CGSize.zero)
EventWebView.scrollView.isScrollEnabled = false;
var frame = EventWebView.frame;

frame.size.width = EventTableView.frame.size.width-40; // Your desired width here.
frame.size.height = 1; // Set the height to a small one.

EventWebView.frame = frame; // Set webView's Frame, forcing the Layout of its embedded scrollView with current Frame's constraints (Width set above).

frame.size.height = EventWebView.scrollView.contentSize.height; // Get the corresponding height from the webView's embedded scrollView.
heightConstraint.constant = frame.size.height

我的 HTML 内容是 "

Testing Description for the new created event by Tester. Testing Description for the new created event by Tester.Testing Description for the new created event by Tester. Testing Description for the new created event by Tester. Testing Description for the new created event by Tester.Testing Description for the new created event by Tester.Testing Description for the new created event by Tester. Testing Description for the new created event by Tester.Testing Description for the new created event by Tester.Testing Description for the new created event by Tester. Testing Description for the new created event by Tester.Testing Description for the new created event by Tester.Testing Description for the new created event by Tester. Testing Description for the new created event by Tester.Testing Description for the new created event by Tester.Testing Description for the new created event by Tester. Testing Description for the new created event by Tester.Testing Description for the new created event by Tester.

\n"

最佳答案

添加 WebViewDelegate

func webViewDidFinishLoad(_ webView: UIWebView) {

webView.frame.size = webView.sizeThatFits(CGSize.zero)
webView.scrollView.isScrollEnabled = false; // Property available in iOS 5.0 and later
var frame = webView.frame;

frame.size.width = self.view.frame.width-20; // Your desired width here.
frame.size.height = 1; // Set the height to a small one.

webView.frame = frame; // Set webView's Frame, forcing the Layout of its embedded scrollView with current Frame's constraints (Width set above).

frame.size.height = webView.scrollView.contentSize.height; // Get the corresponding height from the webView's embedded scrollView.

webView.frame = frame;
fl = webView.frame.size.height

}

请确保同时检查您的自动布局约束。这种方法工作正常。如果您的自动布局设置不正确,那么您可以获得额外的长度。

关于ios - 在 webViewDidFinishLoad 上,我在 swift3 中获得了额外的内容高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39653712/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com