I have a TableViewCell that I want to blink when it’s tapped (ie quickly highlight off and on a couple of times).
So far I’ve implemented this functionality with a timer as follows:
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
NSTimer *blinkTimer = [[NSTimer scheduledTimerWithTimeInterval:.05 target:self selector:@selector(toggleHighlightedMenuCell) userInfo:nil repeats:YES] retain];
self.blinkTimer = blinkTimer;
[blinkTimer release];
}
-(void) toggleHighlightedMenuCell
{
if (self.highlightedMenuCell.isHighlighted)
{
self.highlightedMenuCell.highlighted = NO;
}
else
{
self.highlightedMenuCell.highlighted = YES;
}
self.blinkTimerCounter++;
if (self.blinkTimerCounter == 2)
{
self.blinkTimerCounter = 0;
[self.blinkTimer invalidate];
//execute some code
}
}
The problem with this is it seems to start executing the code in the //execute some code section before it’s finished blinking. Can anyone think of a better way to accomplish this?
Ended up chaining some UIView animations together it ended up working perfectly: