在UITapGestureRecognizer中遇到点击次数问题

时间:2015-12-01 20:21:03

标签: objective-c uitapgesturerecognizer tvos apple-tv

我正在尝试在电视遥控器上运行2次tapping方法,考虑点击点击,但触摸界面不会识别水龙头。而是单击两次运行doubleTapping方法。

UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
    doubleTap.allowedTouchTypes =@[[NSNumber numberWithInteger:UITouchTypeIndirect]];
    doubleTap.numberOfTapsRequired = 2;
    [self.view addGestureRecognizer:doubleTap];



- (void)handleTap:(UITapGestureRecognizer *)sender
{
    if (sender.state == UIGestureRecognizerStateBegan)
    {
        // handling code
        NSLog(@"2 times");
    }
}

我遗失了什么?

1 个答案:

答案 0 :(得分:0)

我忘了提及UIPressType值,现在由于远程表面的位置(向上/向下/向右/向左),您现在可以检测用户的点击方向并将numberOfTapsRequired添加到操作中:

 UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
    [tapGestureRecognizer setAllowedPressTypes:@[@(UIPressTypeLeftArrow)]];
    [tapGestureRecognizer setNumberOfTapsRequired:2];
    [self.view addGestureRecognizer:tapGestureRecognizer];