开发者

How to improve UIWebView scrolling performance?

It seems to be really hard 开发者_JAVA技巧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.

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.

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.

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.

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...


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.


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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜