【问题标题】:Is UIGraphicsBeginImageContext thread safe?UIGraphicsBeginImageContext 线程安全吗?
【发布时间】:2012-07-17 18:41:13
【问题描述】:

所以我一直觉得 UIGraphicsBeginImageContext 是线程安全的,可以从任何线程调用来创建一个新的 CGContextRef 可以用来绘制。

但是,当前的documentation 声明

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

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

如您所见,他向_queue(在BG 线程上运行)添加了一个操作,该操作调用renderedGraphOfSize,该操作调用UIGraphicsBeginImageContext。那么有什么关系呢?在后台绘图时,我的应用程序出现了一些崩溃,所以我不知道为什么 Apple 会出现令人困惑的示例。

【问题讨论】:

    标签: iphone ios cocoa uikit


    【解决方案1】:

    引用文档:

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

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 2020-04-15
        • 2011-07-04
        • 2014-04-26
        • 2012-11-30
        • 2010-12-30
        • 2013-03-12
        • 2021-08-03
        • 2010-12-27
        • 2018-06-04
        相关资源
        最近更新 更多