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.
似乎很难提高UIWebView的性能,特别是对于像Mashable或Ars Technica这样的网站,其中加载了大量脚本并且长篇多页文章很常见。
I'm aware of 3 similar questions, but they both have no working solution:
我知道3个类似的问题,但它们都没有可行的解决方案:
-
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."
UIWebView急剧滚动 - 建议私有API调用 - (void)_setDrawInWebThread:(BOOL)arg1和 - (void)_setDrawsCheckededPattern:(BOOL)arg1,我们知道App Store应用程序不允许这样做
如何使用UIWebView快速,流畅地滚动? - 有人谈到了CATiledLayer,但没有明确指出如何实现它。
在UIWebView上实现CATiledLayer以实现快速滚动--Brad Larson告诉他说“由于其复杂的渲染架构,无法用CATiledLayer手动支持UIWebView。”
I wonder if there're any solutions to this problem. Any suggestions are welcome.
我想知道这个问题是否有任何解决方案。欢迎任何建议。
3 个解决方案
#1
5
I'm afraid there isn't. Big websites remain big and hence consume lots of memory.
我担心没有。大型网站仍然很大,因此消耗大量内存。
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.
我反对Brad Larson:在自己的CATiledLayer中支持webview在技术上是可行的(只需要[webView.layer renderInContext:])但是没有多大意义。平铺层加载延迟,Web视图也是如此。您需要大量精细的代码来检测页面何时完成加载,然后将内容缓存到您的平铺图层等等。
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.
尽管如此,webview实际上已经非常优化。我甚至认为它是整个iOS中最优化的东西之一。它是整个平台中最常用的性能关键组件。每个多行文本都是webview(UITextView是使用它们实现的,例如)。如果webview在某些网站上中断,那么你将很难加快速度。
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...
在某些情况下,不同的解决方案也可以起作用,但前提是您正在寻找特殊目的。如果你不是,那就离开你的手,把时间花在其他地方。只是我的2美分......
#2
1
I don't really know if this can help or is accurate given the question, but here is what I have to say:
鉴于这个问题,我真的不知道这是否有用或者是否准确,但我要说的是:
Some properties like shadow or gradient, and even images inside the WebView affects a lot the performances you can get. Try not to use them and/or to keep them as few as possible.
像阴影或渐变这样的属性,甚至WebView中的图像都会影响很多你可以获得的性能。尽量不要使用它们和/或尽可能少地使用它们。
#3
1
Some web browser applications like iCab and Atomic Web Browser seem to use the _setDrawInWebThread: method, and clearly they are allowed in the app store. If they are not using this method, then they are using something that works identically to it for their UIWebViews. Does anyone know for sure Apple is rejecting apps that use this private API? Could they be letting that one go by "silently"? I'm surprised Apple hasn't made this a public API by now, because any application that uses a UIWebView to display a web page (and there are many high profile apps that do this, FlipBoard for example) makes the device look 'choppy' and sub-par performing...
一些Web浏览器应用程序(如iCab和Atomic Web Browser)似乎使用_setDrawInWebThread:方法,显然它们在应用商店中是允许的。如果他们没有使用这种方法,那么他们正在使用与UIWebViews相同的东西。有没有人知道Apple拒绝使用这个私有API的应用程序?难道他们会“默默地”让那个人过去吗?我很惊讶Apple现在还没有将它变成公共API,因为任何使用UIWebView来显示网页的应用程序(并且有很多高调的应用程序可以执行此操作,例如FlipBoard)使设备看起来“波涛汹涌” '和低于标准的......
#1
5
I'm afraid there isn't. Big websites remain big and hence consume lots of memory.
我担心没有。大型网站仍然很大,因此消耗大量内存。
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.
我反对Brad Larson:在自己的CATiledLayer中支持webview在技术上是可行的(只需要[webView.layer renderInContext:])但是没有多大意义。平铺层加载延迟,Web视图也是如此。您需要大量精细的代码来检测页面何时完成加载,然后将内容缓存到您的平铺图层等等。
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.
尽管如此,webview实际上已经非常优化。我甚至认为它是整个iOS中最优化的东西之一。它是整个平台中最常用的性能关键组件。每个多行文本都是webview(UITextView是使用它们实现的,例如)。如果webview在某些网站上中断,那么你将很难加快速度。
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...
在某些情况下,不同的解决方案也可以起作用,但前提是您正在寻找特殊目的。如果你不是,那就离开你的手,把时间花在其他地方。只是我的2美分......
#2
1
I don't really know if this can help or is accurate given the question, but here is what I have to say:
鉴于这个问题,我真的不知道这是否有用或者是否准确,但我要说的是:
Some properties like shadow or gradient, and even images inside the WebView affects a lot the performances you can get. Try not to use them and/or to keep them as few as possible.
像阴影或渐变这样的属性,甚至WebView中的图像都会影响很多你可以获得的性能。尽量不要使用它们和/或尽可能少地使用它们。
#3
1
Some web browser applications like iCab and Atomic Web Browser seem to use the _setDrawInWebThread: method, and clearly they are allowed in the app store. If they are not using this method, then they are using something that works identically to it for their UIWebViews. Does anyone know for sure Apple is rejecting apps that use this private API? Could they be letting that one go by "silently"? I'm surprised Apple hasn't made this a public API by now, because any application that uses a UIWebView to display a web page (and there are many high profile apps that do this, FlipBoard for example) makes the device look 'choppy' and sub-par performing...
一些Web浏览器应用程序(如iCab和Atomic Web Browser)似乎使用_setDrawInWebThread:方法,显然它们在应用商店中是允许的。如果他们没有使用这种方法,那么他们正在使用与UIWebViews相同的东西。有没有人知道Apple拒绝使用这个私有API的应用程序?难道他们会“默默地”让那个人过去吗?我很惊讶Apple现在还没有将它变成公共API,因为任何使用UIWebView来显示网页的应用程序(并且有很多高调的应用程序可以执行此操作,例如FlipBoard)使设备看起来“波涛汹涌” '和低于标准的......