我不知道这是否是做事的正确方法,但这段代码对我来说效果很好。
@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