问题描述
所以我一直认为 UIGraphicsBeginImageContext 是线程安全的,可以从任何线程调用以创建一个新的 CGContextRef 可以用来绘制.
So I've been under the impression that UIGraphicsBeginImageContext is thread safe, and can be called from any thread to create a new CGContextRef that can be used to draw.
但是,当前的文档 表示
你应该只从应用程序的主线程调用这个函数."
然而,在 WWDC 2012 会议视频构建并发用户界面"中,演讲者表明您实际上可以在后台绘制,并在后台调用该方法:
However, in the WWDC 2012 session video "Building Concurrent User Interfaces", the speaker shows that you can actually draw in the background, and call that method in the background:
如您所见,他向 _queue
(在 BG 线程上运行)添加了一个操作,该操作调用了 renderedGraphOfSize
,后者调用了 UIGraphicsBeginImageContext代码>.那么有什么关系呢?在后台绘图时,我的应用程序发生了一些崩溃,所以我不知道为什么 Apple 有一些令人困惑的示例.
So as you can see, he adds an operation to a _queue
(which runs on a BG thread), which calls renderedGraphOfSize
, which calls UIGraphicsBeginImageContext
. So what's the deal? I am getting some crashes in my app when it comes to drawing in the background, so I don't know why there are confused examples from Apple.
推荐答案
UIGraphicsBeginImageContext 在 iOS 4 及更高版本中绝对是线程安全的.WWDC 2012 会议视频与 iOS 6 相关,所以也许您也应该与 iOS 6 文档相关:)
UIGraphicsBeginImageContext definitely is thread safe in iOS 4 and later.WWDC 2012 session videos relate to iOS 6, so maybe you should relate to iOS 6 documentation as well :)
这篇关于UIGraphicsBeginImageContext 线程安全吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!