Reputation:
In an iPhone application I'm developing I have a Image View that displays eyes and I want to make them blink, an obviously blinking is a random thing, it can't be routine and keep repeating like a UIImageView Animation would do on repeat.
How would I set up an animation that displays one frame (blinked eyes) then sets back to the original image and does this in random intervals?
Remember when answering I'm a newbie.
Upvotes: 1
Views: 2688
Reputation: 518
You could use a NSTimer.
Have the timer's delegate method change the eye image to the blink image, and then set the timer's fire date to a random time.
Once the NSTimer is fired, use this code to set it to a random time:
[yourTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:rand()%maxTimeBetweenBlinks]];
replace yourTimer and maxTimeBetweenBlinks with the right values, of course
You would probably want to use srand(time(NULL)) to seed the random number generator
Upvotes: 0