UIGraphicsBeginImageContext线程安全吗?

时间:2012-07-17 18:41:14

标签: iphone ios cocoa uikit

所以我一直认为UIGraphicsBeginImageContext是线程安全的,并且可以从任何线程调用以创建可用于绘制的新CGContextRef。

但是,当前documentation表示

"You should call this function from the main thread of your application only."

但是,在WWDC 2012会话视频“构建并发用户界面”中,发言人显示您实际上可以在后台绘制,并在后台调用该方法:

enter image description here

enter image description here

enter image description here

正如您所看到的,他向_queue(在BG线程上运行)添加了一个操作,该操作调用renderedGraphOfSize,调用UIGraphicsBeginImageContext。那是什么交易?在我的应用程序中,当我在后台绘图时遇到了一些崩溃,所以我不知道为什么Apple会有一些混乱的例子。

2 个答案:

答案 0 :(得分:1)

引用文档:

  

在iOS 4及更高版本中,您可以从您的任何线程调用此函数   应用

链接:http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIKitFunctionReference/Reference/reference.html

答案 1 :(得分:0)

UIGraphicsBeginImageContext在iOS 4及更高版本中绝对是线程安全的。 WWDC 2012会话视频与iOS 6有关,所以也许您应该与iOS 6文档相关:)

相关问题