Create a UIImage by rendering UIWebView on a background thread - iPhone

℡╲_俬逩灬. 提交于 2019-11-28 23:46:10

UIWebView hates, and I mean really hates, having anything done to it on a background thread. UIKit is not fully thread safe. Drawing to a graphics context is (this was added in iOS 4), but not creating UIViews on a secondary thread.

Are you creating your UIWebViews off the main thread? Do you perhaps have some code to share? I would suspect your issues are being caused by the fact you're trying to perform operations to a UIWebView on a secondary thread. The drawing operation to render the view's contents as an image can happen off the main thread, but creating the view itself can't.

user438350

I've been working on this, too.

In a thread I create a view hierarchy, loop until the web-view has finished loading content.

The webview I create is inside of a UIViewController's viewdidload-- I've tried doing

if ([NSThread isMainThread] == NO) {[self performselectorOnMainThread: @selector(viewDidLoad)return;)}

And I've done the same for dealloc'ing the webView.

But that didn't work.. I've only found that we avoid UIWebView exceptions UNTIL we hit the autorelease pool...

I'm using instruments to figure out why.

Here's my attack strategy... I'm going to perform the render operation on the main thread with an off-screen view, having a separate thread running some sort of queue to manage them. I'm worried about UI lag, so it'll have to be fairly efficient.

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