I am trying to run a method by 2 times
tapping
on tv remote, consider tapping not clicking, but the touch surface does't recognize the taps. Instead, clicking two times runs the doubleTapping
method.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)
{
/
NSLog(@"2 times");
}
}
I am missing something ?
was forgot to mention the
UIPressType
value , now due to position of remote's surface (Up / Down / Right / Left) you can now detect user's tap direction and add numberOfTapsRequired
to the action :UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)]; [tapGestureRecognizer setAllowedPressTypes:@[@(UIPressTypeLeftArrow)]]; [tapGestureRecognizer setNumberOfTapsRequired:2]; [self.view addGestureRecognizer:tapGestureRecognizer];