Multiple Gesture Recognizers

Let’s add another gesture recognizer that allows the user to select a line. (Later, a user will be able to delete the selected line.) You will install another UITapGestureRecognizer on the BNRDrawView that only requires one tap.

In BNRDrawView.m, modify initWithFrame:.

        [self addGestureRecognizer:doubleTapRecognizer];
        
        UITapGestureRecognizer *tapRecognizer =
            [[UITapGestureRecognizer alloc] initWithTarget:self
                                                    action:@selector(tap:)];
        tapRecognizer.delaysTouchesBegan = YES;
        [self addGestureRecognizer:tapRecognizer];
    }

    return self;
}

Now, implement tap: to log the tap to the console in BNRDrawView.m.

- (void)tap:(UIGestureRecognizer *)gr
{
    NSLog(@"Recognized tap");
}

Build and run the application. ...

Get iOS Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.