Does iPhone/iPad UIWebView need to be active view to render?

[亡魂溺海] 提交于 2019-12-07 09:01:07

问题


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];

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

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.


回答1:


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.



来源:https://stackoverflow.com/questions/9853805/does-iphone-ipad-uiwebview-need-to-be-active-view-to-render

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!