Im using Xcode 7.2 currently coding for watchos2, for my app I only want the button to perform a method when they double tap within .5 seconds, if users only single tap then it won't perform the action. For example:
In my .h
#import <WatchKit/WatchKit.h>
#import <Foundation/Foundation.h>
@interface InterfaceController : WKInterfaceController
- (IBAction)btnActivate;
@property (unsafe_unretained, nonatomic) IBOutlet WKInterfaceButton *activateBtn;
@end
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 tweak the afterDelays etc, and clean the code up but this is how I was able to get double taps working