如何判断 UIWebView 何时完成渲染(未加载)?

How do I tell when a UIWebView is done rendering (not loading)?(如何判断 UIWebView 何时完成渲染(未加载)?)

本文介绍了如何判断 UIWebView 何时完成渲染(未加载)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道它何时完成加载...(webViewDidFinishLoad),但我想使用

I know when its done loading... (webViewDidFinishLoad), but I want to use

[webView.layer renderInContext:UIGraphicsGetCurrentContext()];

从 UIWebView 创建图像.有时我会在 webView 完成渲染之前得到图像.我可以使用 performSelector 来延迟图像的获取,但是等待的时间是任意且脆弱的.

to create an image from the UIWebView. Occasionally I get the image prior to the webView finishing its rendering. I can use performSelector to delay the get of the image, but the amount of wait is arbitrary and brittle.

推荐答案

这可能取决于您需要将视图渲染到的图形上下文类型,但您可以调用

This may depend upon the kind of graphics context you need the view rendered into, but you can call

- (void)drawRect:(CGRect)area forViewPrintFormatter:(UIViewPrintFormatter *)formatter

这显然会欺骗 UIWebView 认为它正在被打印.如果您的最终目标是捕获完整页面,这可能会有所帮助.我们最近遇到了一个问题,即使页面已完全加载,调用普通的旧 -drawRect: 如果其中一些不在屏幕上,也不会呈现整个页面.

which apparently tricks the UIWebView into thinking that it's being printed. This may help if your ultimate goal is to capture the complete page. We've had the problem recently in which even if the page was fully loaded, calling plain old -drawRect: didn't render the entire page if some of it was offscreen.

这篇关于如何判断 UIWebView 何时完成渲染(未加载)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何判断 UIWebView 何时完成渲染(未加载)?