Im using Xcode 7.2, currently encoding watchos2, for my application, I want the button to execute the method when they double-tap for 0.5 seconds, if users only have one click, then this will not perform the action. For instance:
In my .h
At the top of my .m file, I declared:
int taps = 1; - (IBAction)btnActivate { taps = taps + 1; if (taps == 2){ [activateBtn setBackgroundColor:[UIColor grayColor]]; [self performSelector:@selector(tapOne:) withObject:self afterDelay:0.5]; } else if (taps == 3){ [self performSelector:@selector(tapTwo:) withObject:self afterDelay:0]; [activateBtn setEnabled:NO]; [activateBtn setBackgroundColor:[UIColor redColor]]; } else { //Do other things here if you want } } - (void) tapOne: (id) sender{ if (taps == 2){ [self performSelector:@selector(afterTapDone:) withObject:self afterDelay:1]; } else { } } - (void) tapTwo: (id) sender { //Perform button actions here when user double taps [self performSelector:@selector(afterTapDone:) withObject:self afterDelay:10]; } - (void) afterTapDone: (id) sender { taps = 1; [activateBtn setEnabled:YES]; [activateBtn setBackgroundColor:[UIColor colorWithRed:0/255.0f green:174/255.0f blue:239/255.0f alpha:1.0f]]; [activateBtn setTitle:@"Activate"]; }
Of course, you can configure afterDelays, etc., and clear the code, but this is how I was able to get double taps working
source share