---
title: "Tap Gesture Recognizer in iOS"  
description: "Here we will learn about UITapGestureRecognizer class, and see how can we it in our iOS applications."  
author: "Tarun Kumar"  
published: 2015-11-29  
updated: 2019-07-18  
canonical: https://www.mindstick.com/articles/11926/tap-gesture-recognizer-in-ios  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 2 minutes  

---

# Tap Gesture Recognizer in iOS

Whenever we are creating an app for iPhone/iPad touch [devices](https://www.mindstick.com/blog/301912/how-smart-devices-are-changing-our-lives) we always use tap gestures to recognize or taking some actions. In iOS tap gestures are registered with the UITapGestureRecognizer class. Here we will show you how to use this class to recognize single and [multiple](https://www.mindstick.com/blog/12797/iowa-is-expected-to-see-heavy-growth-in-multiple-sectors) tap gestures.

##### Here we are providing some points to remember:

1. First of all we will enable user [interaction](https://yourviews.mindstick.com/view/80771/technology-is-destroying-human-interaction-how) on the UI element that's going to receive the taps. We can do this by setting the UserInteractionEnabled [property](https://www.mindstick.com/articles/198559/an-ownership-of-property-in-hua-hin) to true like that:

imageView.UserInteractionEnabled = true;

We can also do it inside the ViewDidLoad method of the [ViewController](https://www.mindstick.com/forum/33628/viewcontroller-s-viewdidunload-method-deprecated-in-ios-6) or any

other method that we are using to manipulate our apps UI elements.

2. After that, we will create a new UITapGestureRecognizer and passing [action](https://yourviews.mindstick.com/view/81713/strict-action-needed-on-counterfeit-drugs-in-india)

name which will handle the tap [gesture](https://www.mindstick.com/blog/11625/sending-valentine-flowers-is-a-beautiful-gesture) like this:

UITapGestureRecognizer tapGesture = new UITapGestureRecognizer (TapedImage);

3. After that we will create an action which handles the tap gestures. Here we are

created a [method called](https://www.mindstick.com/interview/2613/when-does-onresume-method-called) TapedImage to rotate clockwise view(90 degrees) and

show an alert view:

tap.View.Transform *= CGAffineTransform.MakeRotation ((float)Math.PI / 2);\
tapped = true;\
alert = UIAlertController.Create ("Image is Tapped", UIAlertControllerStyle.Alert);\
alert.AddAction (UIAlertAction.Create ("OK", UIAlertActionStyle.[Default](https://www.mindstick.com/interview/12771/what-is-the-importance-of-default-resources), null));\
ViewController (alert, true, null);

4. Now, at last we will add the gesture recognizer in our UI element, like this:

imageView.AddGestureRecognizer (tapGesture);

We can also count the number of taps using gesture recognizer, it will responds by

using NumberOfTapsRequired property of the tap gesture recognizer.

\

##### For Example:

numberOfGesture.NumberOfTapsRequired = 2;

(by default number of taps [required](https://yourviews.mindstick.com/view/81031/vigilence-required-during-corona-pandemic) is 1)

---

Original Source: https://www.mindstick.com/articles/11926/tap-gesture-recognizer-in-ios

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
