私は現在watchos2のコーディングをしているXcode 7.2を使用しています。私のアプリでは、.5秒以内にダブルタップしたときにボタンにメソッドを実行させたいだけです。例えば:
私の.hで
#import <WatchKit/WatchKit.h>
#import <Foundation/Foundation.h>
@interface InterfaceController : WKInterfaceController
- (IBAction)btnActivate;
@property (unsafe_unretained, nonatomic) IBOutlet WKInterfaceButton *activateBtn;
@end
.m ファイルの先頭で次のように宣言しました。
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"];
}
もちろん、afterDelays などを微調整してコードをクリーンアップすることもできますが、これでダブルタップを機能させることができました。