I’d like to create a flicker effect, similar to a fluorescent light turning on. The sequence will take around 2 seconds. As it’s on a black background (and the image is white) I could adjust the alpha in a sequence like this:
0.5sec Alpha = 1.0;
0.15sec Alpha = 0.0;
0.4sec Alpha = 1.0;
0.35sec Alpha = 0.0;
0.3sec Alpha = 1.0;
0.1sec Alpha = 0.0;
~ Alpha = 1.0;
At this point, the alpha is at 1.0 and id like to leave it there. The problem is that I cant just change the values, as they would just get queued up for drawing and wouldn’t happen immediately, instead they’d all happen at once next time the UI is drawn, leaving me with no flicker effect.
Neither can I use a UIView.animate block, as this will tween/animate the view’s alpha over the times specified, I dont want it smoothed out, I want it to instantly flicker between the alpha levels.
I could possibly use UIImageView image frame animation, but was wondering is there a cleaner, faster, easier method?
Use a NSTimer. This is what I would do (psuedo-code):
if you have some pattern to the flicker you can make something better than a long switch and maybe just have something like
if (timeSpent % 5 == 0) { alpha = 1.0; } else { alpha = 0.0; }EDIT: How about something like this: