iPhone / iPad UIWebView需要是活动视图来渲染吗? [英] Does iPhone/iPad UIWebView need to be active view to render?

查看:63
本文介绍了iPhone / iPad UIWebView需要是活动视图来渲染吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将屏幕外的网页呈现为位图,然后向用户显示位图。这可以通过主线程上的简单代码完成,如下所示:

I need to render a web page offscreen to a bitmap, then show the bitmap to the user. Can this be done with simple code on the main thread like this:

NSString *urlAddress = @"http://www.google.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[offscreenWebView loadRequest:requestObj];

或者我是否需要将UIWebView附加到活动视图?

Or do I need to attach the UIWebView to an active view?

在Android中,除非视图是活动视图的一部分,否则Web视图似乎不会呈现。因此,要在Android中执行此任务,我需要创建一个视图层次结构,为Web渲染器创建一个活动视图,然后在其上面放置另一个视图以让它在屏幕外绘制。

In Android, the web view seems not to render unless it is part of an active view. So to do this task in Android, I need to create a view hierarchy, create an active view for the web renderer, and then put another view on top of it to let it draw offscreen.

推荐答案

我自己一直在努力解决这个问题。除非将UIWebView添加到UIWindow对象,否则它不会呈现。但是,这不一定是您用来显示应用程序的窗口。你可以创建一个单独的UIWindow对象,并将UIWebView附加到它,它将呈现得很好。但是,UIWebView渲染是一个缓慢的过程,因此它在准备好之前会有一个短暂的延迟。完成后,它会将webViewDidFinishLoad方法触发到其委托。

I struggled with this problem for a while myself. UIWebView will not render unless it is added to a UIWindow object. However, this does not have to be the window you are using to show your app. You can make a separate UIWindow object, and attach the UIWebView to that and it will render just fine. However, UIWebView rendering is a slow process, so it will have a short delay before it is ready. When it is done, it will fire the webViewDidFinishLoad method to its delegate.

这篇关于iPhone / iPad UIWebView需要是活动视图来渲染吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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