开发者

Use progress bar in UIWebView?

Is it possible to use a progress bar with a UIWebView when loading w开发者_如何学JAVAeb pages, as Safari does in the address bar? I read that you need to use a private API, which Apple doesn't allow, but that doesn't seem right... you can't detect how large a page is and update the progress bar with the amount downloaded?


For this kind of thing, you can only really 'detect' page size by using Content-Length headers, but otherwise you can still present a loading control (like one of the moving zebra crossing type bars which doesn't show a discrete % progress but shows that activity is occurring.. or even just a UIActivityIndicator). You could try a ready-made class like ASIWebPageRequest too, which CAN show progress. The author states:

ASIWebPageRequests do not currently support progress tracking for an entire request with its external resources. However, progress updates from external resource requests are passed on to your delegate, so with a bit of work it may be possible to implement this yourself.


If you were the browser, then you'd have access to the intial HTTP response's Content-Length response header. Then you might also decide to tack on to this size the result of any sub-requests that come in, via JavaScript, images, etc.

MobileSafari can eventually tell how big each request is, add them all up, then provide info to you on the overall download progress.

Not sure what you're trying to do, but this is how they accomplish it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜