iOS - 强制 UIWebView 加载内容?

发布于 2024-12-12 02:11:59 字数 294 浏览 0 评论 0原文

我使用 loadHtmlString: 设置 UIWebView 的内容。我不会将它们添加到 UIView 直到需要它们,但我需要知道它们每个的最大滚动高度。

问题是 UIWebView 在添加到 superView 之前不会开始加载其数据,并且加载内容的延迟导致了此问题。

问题:是否可以强制 UIWebView 加载其内容,而不将其添加到视图中?

I set the content of a UIWebView using loadHtmlString:. I don't add them to the UIView until they are need, but I need to know the max scroll height of each of them.

The problem is that UIWebView doesn't start loading it's data until it's added to a superView, and It's the delay of loading content that is causing this problem.

Question: Is it possible to force a UIWebView to load its content, without being added to a view?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

笑,眼淚并存 2024-12-19 02:11:59

您可以将其添加到视图中并将其不透明度设置为 0.01 以强制加载。我以前必须用 MKMapView 这样做。

You can add it to the view and set it's opacity to 0.01 to force the load. I've had to do this with MKMapView before.

极度宠爱 2024-12-19 02:11:59

我会使用 UIWebViewhidden 属性 - 在添加视图之前将其设置为 YES 并将其清除为 NOwebViewDidFinishLoad: 中应该可以解决问题。

然而,您对 @logancautrell 的回答的评论有点令人不安 - 您是否计划将那么多网络视图添加到您的视图中?我假设您知道这一点,但以防万一:根据您可能的 HTML(5)/JavaScript/CSS 代码,即使 iOS 需要为其分配大量资源的少量 Web 视图,您也可能会观察到严重的性能影响。

如果您计划经常更新 Web 视图,也许您可​​以从 UIWebView 的 stringByEvaluatingJavaScriptFromString: 方法中受益?我认为,在某种程度上,性能受到的影响是可以忍受的。

I'd use hidden property of UIWebView - setting it to YES before view is added and clearing it to NO in webViewDidFinishLoad: should do the trick.

However, you comment to @logancautrell's answer is a bit unsettling - do you ever plan to get that many web views added to your views? I assume you know that, but just in case: depending on your possible HTML(5)/JavaScript/CSS code, you may observe severe performance hit even with a small number of web views for which iOS needs to allocate lots of resources.

If you plan to update your web views often, maybe you could benefit from UIWebView's stringByEvaluatingJavaScriptFromString: method? To some extent, the performance hit can be bearable, I think.

荒人说梦 2024-12-19 02:11:59

我建议要么以某种方式预先计算滚动高度(不是在 Web 视图加载期间),要么找到一种方法来显示 UIViews,而不需要等待滚动高度,然后再纠正它们。

I suggest either pre-calculating the scroll heights somehow (not during web view load), or finding a way to display your UIViews without waiting for the scroll heights initially, and correct them later.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文