Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="https://developer.apple.com/library/ios/#releasenotes/General/WhatsNewIniPhoneOS/Articles/iPhoneOS4.html#//apple_ref/doc/uid/TP40009559-SW29" rel="noreferrer"><em>What's New in iOS: iOS 4.0</em></a> says this:</p> <blockquote> <ul> <li>Drawing to a graphics context in UIKit is now thread-safe. Specifically: <ul> <li>The routines used to access and manipulate the graphics context can now correctly handle contexts residing on different threads.</li> <li>String and image drawing is now thread-safe.</li> <li>Using color and font objects in multiple threads is now safe to do.</li> </ul></li> </ul> </blockquote> <p>It sounds like you tried something like this:</p> <pre><code>UIGraphicsBeginImageContextWithOptions(size,false,0); dispatch_async(someQueue, ^{ [UIColor.whiteColor setFill]; UIRectFill(0, 0, 20, 20); dispatch_async(dispatch_get_main_queue(), ^{ UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); self.imageView.image = image; }); }; </code></pre> <p>That won't work because each thread has its own stack of graphics contexts (starting in iOS 4.0). You need to do it like this:</p> <pre><code>dispatch_async(someQueue, ^{ UIGraphicsBeginImageContextWithOptions(size,false,0); [UIColor.whiteColor setFill]; UIRectFill(0, 0, 20, 20); UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); dispatch_async(dispatch_get_main_queue(), ^{ self.imageView.image = image; }); }; </code></pre> <h3>UPDATE</h3> <p>The <a href="https://developer.apple.com/library/ios/documentation/uikit/reference/UIKitFunctionReference/Reference/reference.html" rel="noreferrer">documentation</a> for <code>UIGraphicsBeginImageContextWithOptions</code> and other UIKit graphics functions now says</p> <blockquote> <p>In iOS 4 and later, you may call this function from any thread of your app.</p> </blockquote> <p>The <a href="https://developer.apple.com/library/ios/documentation/uikit/reference/UIColor_Class/Reference/Reference.html" rel="noreferrer">documentation</a> for <code>UIColor</code> says</p> <blockquote> <p>Color objects are immutable and so it is safe to use them from multiple threads in your app.</p> </blockquote> <p>The <a href="https://developer.apple.com/library/ios/documentation/uikit/reference/UIFont_Class/Reference/Reference.html" rel="noreferrer">documentation</a> for <code>UIFont</code> says</p> <blockquote> <p>Font objects are immutable and so it is safe to use them from multiple threads in your app.</p> </blockquote> <p><strong>However</strong>, the <a href="https://developer.apple.com/library/iOs/documentation/UIKit/Reference/NSString_UIKit_Additions/Reference/Reference.html" rel="noreferrer">documentation</a> for the UIKit <code>NSString</code>-drawing additions says</p> <blockquote> <p>The methods described in this class extension must be used from your app’s main thread.</p> </blockquote> <p>So you must <strong>not</strong> try something like <code>[@"hello" drawAtPoint:CGPointZero withAttributes:attrs]</code> from a background thread.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload