我不知道這是否是做事的正確方法,但這段代碼對我來說效果很好。
@interface MyViewController : UIViewController {
int tapCount;
}
@property (nonatomic, assign)int tapCount;
@end
在我的.m文件
:
在我.h文件中
@synthesize tapCount;
- (void)tapGesture:(UIGestureRecognizer*)gesture {
tapCount = tapCount + 1;
[self performSelector:@selector(correctTapCount) withObject:nil afterDelay:0.3];
}
-(void)correctTapCount {
if (tapCount == 1) {
NSLog(@"Single Tap");
}
if (tapCount == 2) {
NSLog(@"Double Tap");
}
//reset TapCount
tapCount = 0;
}
而這正是我加入我的自來水監聽器(它是一個UIImageView)
//add tap listener
carImage.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesture:)];
[carImage addGestureRecognizer:tap];
[tap release];
好運和快樂編碼!
您可能想要指定您詢問的平臺。 – retracile 2009-08-15 18:30:36
縮回,檢查標籤。 – JoshJordan 2009-08-15 18:31:28
@retracile:在這個問題上有一個「iphone」標籤(當然,也許35秒前,當你發佈你的評論時,它就不存在);所以,我猜它是在iphone平臺上;-) – 2009-08-15 18:31:55