如何提高UIWebView滚动性能? [英] How to improve UIWebView scrolling performance?

查看:150
本文介绍了如何提高UIWebView滚动性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎很难提高UIWebView的性能,特别是对于像Mashable或Ars Technica这样的网站,这些网站加载了大量脚本,并且长篇多页文章很常见。

It seems to be really hard to improve the performance of a UIWebView, especially for websites like Mashable or Ars Technica, where tons of scripts are loaded and long, multi-page articles are common.

我知道3个类似的问题,但他们都没有可行的解决方案:

I'm aware of 3 similar questions, but they both have no working solution:

  • UIWebView scrolls jerkily - private API calls like -(void)_setDrawInWebThread:(BOOL)arg1 and -(void)_setDrawsCheckededPattern:(BOOL)arg1 are suggested, and we know that they aren't allowed in App Store apps
  • How to get fast, smooth scrolling with UIWebView? - someone talked about CATiledLayer, but there was no clear pointer as to how to implement that.
  • Implementing CATiledLayer on a UIWebView for fast scrolling - Brad Larson told that "there's no way to manually back a UIWebView with a CATiledLayer, due to its complex rendering architecture."

我想知道是否有任何解决方案可以解决这个问题。欢迎任何建议。

I wonder if there're any solutions to this problem. Any suggestions are welcome.

推荐答案

我担心没有。大网站仍然很大,因此消耗大量内存。

I'm afraid there isn't. Big websites remain big and hence consume lots of memory.

我反对Brad Larson:在自己的CATiledLayer中支持webview在技术上是可行的(只需要 [webView.layer renderInContext:] )但没有多大意义。平铺层加载延迟,Web视图也是如此。你需要大量精细的代码来检测页面何时完成加载,然后将内容缓存到你的平铺层等等。

I'd argue against Brad Larson: backing a webview in a own CATiledLayer is technically possible (just do [webView.layer renderInContext: ]) but does not make a lot of sense. Tiled layers load lazily, as do web views. You'd need a enormous amount of finetuned code to detect when the page finished loading, then to cache things into your tiled layer and so on.

尽管如此,webview实际上是非常优化的。我甚至认为它是整个iOS中最优化的东西之一。它是整个平台中最常用的性能关键组件。每个多行文本都是webview(UITextView是使用它们实现的,例如)。如果webview在某些网站上中断,你将很难加快速度。

Despite that, the webview is actually quite optimized. I'd even argue that it's one of the best-optimized things in the whole iOS. It's the single-most-used performance critical component across the whole platform. Every multi-line text is a webview (UITextView is implemented using them, e.g). If the webview breaks on some website, you'll have quite a hard time making it faster.

有些情况下,不同的解决方案也可能有效,但仅限于你正在寻找特殊目的。如果你不是,那就离开你的手,把时间花在其他地方。只是我2美元......

There are cases where a different solution might work as well, but only if you're looking for something special purpose. If you're not, then leave your hands off and invest the time somewhere else. Just my 2 cent...

这篇关于如何提高UIWebView滚动性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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