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

前端 未结 2 2000
忘掉有多难
忘掉有多难 2020-12-15 10:50

Does someone know of a way, or has a creative idea as to how to obtain an UIImage that is rendered from a UIWebView? The catch is, that is must be on a background thread.

2条回答
  •  时光取名叫无心
    2020-12-15 11:30

    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.

提交回复
热议问题