我正在尝试在电视遥控器上运行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");
}
}
我遗失了什么?
答案 0 :(得分:0)
我忘了提及UIPressType
值,现在由于远程表面的位置(向上/向下/向右/向左),您现在可以检测用户的点击方向并将numberOfTapsRequired
添加到操作中:
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
[tapGestureRecognizer setAllowedPressTypes:@[@(UIPressTypeLeftArrow)]];
[tapGestureRecognizer setNumberOfTapsRequired:2];
[self.view addGestureRecognizer:tapGestureRecognizer];