0

Possible Duplicate:
Safe way to render UIVIew to an image on background thread?

I am trying to implement some HUD code. The HUD is and activity indicator to give some feedback to users during long operations of course. As I understand it, the HUD must be run on the main thread, as it it a UI operation, but I also understand that if other operations are a UI operation they also needs to run on the main thread. I assume running CoreImage filters (for instance) would be an example of something that could be run off the main thread, but adding the resultant UIImages images to UIImageView would need to be run on the main thread. Am I correct? What about [[aView layer] renderInContext:UIGraphicsGetCurrentContext()]? Can this be run off the main thread?

How can I determine exactly which operations need to be run on the main thread?

Thanks for reading.

Community
  • 1
  • 1
OWolf
  • 5,012
  • 15
  • 58
  • 93

1 Answers1

1

What about [[aView layer] renderInContext:UIGraphicsGetCurrentContext()]? Can this be run off the main thread?

What is a view? It's part of the interface. What is a layer? It's part of the interface. Don't touch the interface except in the main thread.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • In that case what if renderInContext takes a good deal of time to complete, how would I add an effective HUD to keep the interface responsive? – OWolf Dec 28 '12 at 08:04
  • I don't understand the question. (1) If there's a HUD, why does the interface need to be responsive? Doesn't the HUD mean "please wait and do nothing?" (2) The built-in activity indicator spins for you. (3) Do you understand about how to get off and on the main thread? You can do anything you like in the background. Just get back on the main thread for those moments where you touch the interface. – matt Dec 28 '12 at 16:31
  • Yes I understand how to get off and on the main thread. The issue is that, from what I understand, it is recommended that the HUD, being a view, needs to be on the main thread. So, if a long process is also on the main thread, from my experience, the activity indicator will not spin while the long process on the main thread is active. Thanks for reading! – OWolf Dec 29 '12 at 02:35
  • The activity indicator will spin if you start it on the main thread and then get off the main thread and then back onto it (using delayed performance). – matt Dec 29 '12 at 04:35