objectiveccoder001
objectiveccoder001

Reputation: 3031

Strobe iPhone background - NSTimer?

I want to set up a simple strobe of the background. I'd like to have a variable for frequency. Is NSTimer the best way to do this? If so, how?

Thinking of maybe doing something like this:

LOOP OF SOME KIND() {
self.window.backgroundColor = [UIColor redColor];
//DELAY - the amount is the frequency
self.window.backgroundColor = [UIColor blackColor];
}

FYI, I have a UISlider that's outputting values 0 to 255 for the frequency. So, 0 is no strobe. 255 is very fast strobe.

Thanks!

Upvotes: 0

Views: 154

Answers (1)

Bastian
Bastian

Reputation: 10433

Instead of NSTimer you could use a CADisplayLink for that.

http://developer.apple.com/library/ios/#documentation/QuartzCore/Reference/CADisplayLink_ClassRef/Reference/Reference.html

just save the timestamp when you last changed the color and if enough time passed change it again in the displaylink function.

Upvotes: 1

Related Questions