繁体   English   中英

点击手势识别器太慢

[英]Tap Gesture Recognizer too slow

我很难获得UITapGestureRecognizer来检测正在发生的每个点击。 对于上下文,我正在制作鼓点应用程序。 我已经让水龙头手势识别器正常工作,但是用户应该能够非常快速地敲击鼓,并且识别器只是轻轻一点,所以经常使用水龙头(如果你试图尽可能快地点击) )。

我猜这与iOS分类连续快速分类作为一个手势有关,但有没有办法让每次手指下来作为点击事件?

我尝试过使用UILongPressGestureRecognizerUILongPressGestureRecognizer时间很短。

我尝试将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属性
  • 如果您的视图嵌入在UIScrollView或任何派生类中,请检查delaysContentTouches属性

虽然我很欣赏每个人的意见,但我自己也想到了。

在我的代码中,我正在运行一个关键帧动画,其选项设置为0 这意味着在动画期间,用户与视图的交互未启用。

通过将options设置为UIKeyframeAnimationOptionAllowUserInteraction ,即使其中一个子视图仍处于动画UIKeyframeAnimationOptionAllowUserInteraction ,我也可以选择点击。

希望这有助于其他人!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM