Implementing tap

Tap is a gesture in which you quickly touch and remove the finger from the screen. There is a separate gesture recognizer for this as well.

Getting started

To get ready, no additional work is required.

How to do it…

Similarly to the swipe gesture recognizer, we just have to assign a function that will get called once the gesture is recognized. Add the following code to the class:

UITapGestureRecognizer* tapGestureRecognizer = [[UITapGestureRecognizeralloc] initWithTarget:self action:@selector(handleTap:)];
[[UIApplicationsharedApplication].delegate.windowaddGestureRecognizer:tapGestureRecognizer];

Here, we will create a variable of the UITapGestureRecognizer type, allocate and initialize it with a function, and set the delegate as self.

Next, add the following function that will get called once the tap is complete:

- (void)handleTap:(UIGestureRecognizer*)recognizer {

  NSLog(@"TAP");
}

Now, your class can recognize the taps.

How it works…

Now, tap the screen if you are running on the device or left-click on the simulator to see the output in the console.

How it works…
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.145.82