我很难让 UITapGestureRecognizer
检测每一次点击。对于上下文,我正在制作一个击鼓应用程序。我已经让敲击手势识别器正常工作,但用户应该能够非常快速地敲击鼓,并且识别器只是在让我们说每隔一段时间敲击一次(如果你尝试尽可能快地敲击) ).
我猜这与 iOS 将非常快速的连续点击归类为一个手势有关,但是有什么方法可以将每次手指放下作为点击事件吗?
我尝试过使用 UILongPressGestureRecognizer
并按下持续时间很短。
我已尝试将 requiredNumberofTouches
和 requiredNumberofTaps
设置为 1。
似乎没有必要为了回答问题而发布代码,但如果您要求,我会发布。
如有任何帮助,我们将不胜感激!
编辑:我正在添加我的代码,因为它可能有帮助:
-(void)tap:(UITapGestureRecognizer *)tapGestureRecognizer {
CGPoint location = [tapGestureRecognizer locationInView:[self view]];
switch ([self validateTouchLocation:location]) {
case 0:
return;
case 1:
[[ASSoundManager sharedManager] playSoundNamed:@"SD0025" ofType:@"mp3"];
break;
case 2:
default:
[[ASSoundManager sharedManager] playSoundNamed:@"SD0010" ofType:@"mp3"];
break;
}
float tapWidth = 30;
ASDrumTapView *drumTapView = [[ASDrumTapView alloc] initWithFrame:CGRectMake(location.x - (tapWidth / 2), location.y - (tapWidth / 2), tapWidth, tapWidth)];
[drumTapView setBackgroundColor:[UIColor clearColor]];
[drumTapView setNeedsDisplay];
[[self view] addSubview:drumTapView];
float animDuration = 0.75;
CGRect frame = [drumTapView frame];
[UIView animateKeyframesWithDuration:animDuration
delay:0.0
options:0
animations:^{
[UIView addKeyframeWithRelativeStartTime:0
relativeDuration:animDuration
animations:^{
[drumTapView setFrame:CGRectInset(frame, -frame.size.width, -frame.size.height)];
}];
[UIView addKeyframeWithRelativeStartTime:0
relativeDuration:3*animDuration/5
animations:^{
[[drumTapView layer] setOpacity:0.0];
}];
}
completion:^(BOOL finished) {
[drumTapView removeFromSuperview];
}];
}
最佳答案
可能有很多原因:
- 一个可能的原因是您的音频引擎无法在上一个声音播放完之前播放下一个声音。
- 检查
UIView
上的multipleTouchEnabled
属性 - 如果您的 View 嵌入在
UIScrollView
或任何派生类中,请检查delaysContentTouches
属性
关于ios - 点击手势识别器太慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33644000/