Question

I created something that is recognizing double taps on a UIView. The action is sent trough a selector. However, it will only register the double tap once. I want it to run multiple times. I think one way of fixing it is to set the registered taps to 0 again, or using a timer or something. I'll appreciate every answer, thanks.

UITapGestureRecognizer *DoubleClick = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(DoubleClickRegistered:)];
    DobbelKlikk.numberOfTapsRequired = 2;
    [self.view addGestureRecognizer:DobbelKlikk];
Was it helpful?

Solution

I abstracted this out so that you can see that it will work. The problem is something in your selector it has nothing to do with the UITapGestureRecognizer

UITapGestureRecognizer *tapRecog = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(weeee)];
tapRecog.numberOfTapsRequired = 2;

[self.view addGestureRecognizer:tapRecog];

- (void)weeee
{
    NSLog(@"Two taps");
    self.wee = !self.wee;

    if (!self.wee) {
        self.view.backgroundColor = [UIColor redColor];
        NSLog(@"Wee is false");
    } else {
        self.view.backgroundColor = [UIColor whiteColor];
        NSLog(@"Wee is true");
    }
}

If you add that to a project (include a BOOL property for wee and set it in viewDidLoad) every time you double tap the background color will change.

With regards to your code I would recommend setting some break points and figuring out what values are set and what they're set to. Somewhere, there is something thats not happening the way you're expecting it to happen. For example if isTorchActive is never true, then it'll always switch to white. I don't know where you're setting that, but that is most likely the problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top