views:

330

answers:

1

I'm using a NSTimer to fire a drawRect within the app's main view. The drawRect draws a few images, and blends each using kCGBlendModeScreen (which is an absolute must). However, the drawRect takes just a tad longer than desired, so the timer doesn't always get fired at the desired rate (more like half as often).

I've optimized the graphics used as much as I feel is possible, so I'm wondering if it's possible to "outsource" the drawing by creating a new view, and calling that view's drawRect from within a thread created inside of the timer's callback method. (In other words, thread the call to a new view's drawRect, such as [someNewView setNeedsDisplay] ...)

If so, how might I approach something like that, in code?

...

I'd use Core Animation, but I remember reading that it didn't support alpha blend modes. If I'm wrong, I'd be open to seeing some example code that allows animation of all the images in separate transformations (e.g. individual rotations for each image), while still keeping them able to blend using kCGBlendModeScreen that I'm currently implementing.

Thanks for any tips!

+1  A: 

The answer is "no." You should never, ever do drawing(or anything with UIKit) from a secondary thread. If you're experiencing performance issues, you should perform all of your computations on another thread ahead of drawing so that drawing takes a minimal amount of time.

Mike
It's definitely not the calculations that are taking the time, it's the drawing itself. So then, how about my questions regarding CA?I have researched the topic quite a bit with little definitive results (code-wise), but maybe I'm just not searching on the right keywords?
steganous
Unfortunately, it's not likely that using CA will improve performance. If all you're doing is drawing images with `kCGBlendModeScreen`, I can't see why CA would be faster. Is there any way you can pre-render images?
Mike
No, I would have to pre-render hundreds of thousands of images. But CA uses OpenGL, so I would expect to to speed things up a bit, even if it is just a slight speed up.
steganous
I was just hoping to ovoid the complexities or OpenGL, though I figure I'm just delaying the inevitable in the end anyway.
steganous