四种可能的解决方案
我认为你的方法很好
- (void)quantityChanged:(UITapGestureRecognizer *)tapRecognizer {
static NSUInteger numberOfTaps;
if (tapRecognizer.state == UIGestureRecognizerStateEnded) {
numberOfTaps ++;
NSLog(@"web service call with %d",numberOfTaps);
}
}
查看日志
web service call with 1
web service call with 2
web service call with 3
web service call with 4
或者
触发后删除 quantityChanged UITapGestureRecognizer
我的意思是,从发件人对象中删除 UITapGestureRecognizer(在您的第一个 Web 服务之后的 quantityChanged 方法内)
然后在您收到第一个 Web 服务响应后,再次将 UITapGestureRecognizer 添加到发件人。
或者
使用 UILongPressGestureRecognizer 。这是一个漫长的事件过程。请检查事件状态,无论是开始、完成等,然后编写您的代码。
- (IBAction)longPressDetected:(UIGestureRecognizer *)gestureRecognizer {
if (gestureRecognizer.state == UIGestureRecognizerStateBegan){
NSLog(@"Long press began");
} else if ( gestureRecognizer.state == UIGestureRecognizerStateRecognized ) {
NSLog(@"Long press UIGestureRecognizerStateRecognized");
}
else if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {
NSLog(@"Long press Ended");
}
else {
NSLog(@"Long press detected.");
}
}
或者
为 UITapGestureRecognizer设置numberOfTapsRequired
UITapGestureRecognizer *doubleTapRecognizer = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(beginComicTransitions:)] autorelease];
doubleTapRecognizer.numberOfTapsRequired = 2;
doubleTapRecognizer.numberOfTouchesRequired = 1;
doubleTapRecognizer.delegate = self;