Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
511 views
in Technique[技术] by (71.8m points)

iphone - Is UIGraphicsBeginImageContext thread safe?

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.

However, the current documentation states that

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

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:

enter image description here

enter image description here

enter image description here

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To quote from the documentation:

In iOS 4 and later, you may call this function from any thread of your app.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...