ios - 点击手势识别器太慢

标签 ios objective-c iphone uigesturerecognizer

我很难让 UITapGestureRecognizer 检测每一次点击。对于上下文,我正在制作一个击鼓应用程序。我已经让敲击手势识别器正常工作,但用户应该能够非常快速地敲击鼓,并且识别器只是在让我们说每隔一段时间敲击一次(如果你尝试尽可能快地敲击) ).

我猜这与 iOS 将非常快速的连续点击归类为一个手势有关,但是有什么方法可以将每次手指放下作为点击事件吗?

我尝试过使用 UILongPressGestureRecognizer 并按下持续时间很短。

我已尝试将 requiredNumberofTouchesrequiredNumberofTaps 设置为 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/

相关文章:

iphone - 收到推送通知后更改选定的选项卡

objective-c - 使用 contentLayoutGuide 进行约束

objective-c - 更改 xib 文件的背景颜色?

ios - Ios UITableview 中的自适应表格 View 单元格

iphone - 复制内容并删除 webview 时 UIWebview 崩溃

ios - 以编程方式将搜索栏和 UISearchDisplayController 添加到 UITableView

ios - ID警告:找不到选项目录

javascript - 检测 UIWebView 是否可以在 iPhone 上内联播放视频 ( allowsInlineMediaPlayback )

ios - 为 react-native 添加了 IOS QuickLook 框架

ios - 在后台运行的 GPS 应用程序