Reputation: 3031
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
Reputation: 10433
Instead of NSTimer
you could use a CADisplayLink
for that.
just save the timestamp when you last changed the color and if enough time passed change it again in the displaylink function.
Upvotes: 1