UITapGestureRecognizer 中的点击次数有问题
Having issue with number of taps in UITapGestureRecognizer
我正在电视遥控器上尝试 运行 两次 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");
}
}
我错过了什么?
我忘了提到 UIPressType
值,现在由于遥控器表面的位置(上/下/右/左),您现在可以检测用户的点击方向并将 numberOfTapsRequired
添加到动作:
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
[tapGestureRecognizer setAllowedPressTypes:@[@(UIPressTypeLeftArrow)]];
[tapGestureRecognizer setNumberOfTapsRequired:2];
[self.view addGestureRecognizer:tapGestureRecognizer];
我正在电视遥控器上尝试 运行 两次 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");
}
}
我错过了什么?
我忘了提到 UIPressType
值,现在由于遥控器表面的位置(上/下/右/左),您现在可以检测用户的点击方向并将 numberOfTapsRequired
添加到动作:
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
[tapGestureRecognizer setAllowedPressTypes:@[@(UIPressTypeLeftArrow)]];
[tapGestureRecognizer setNumberOfTapsRequired:2];
[self.view addGestureRecognizer:tapGestureRecognizer];