Swipe Gesture Recognizer

Updated 24 September 2021


Swipe Gesture Recognizer is a very common and important feature. it is used when we drag a finger towards a direction (left, right, top, down).

An example of the swipe gesture exists in the photos gallery app where we use swipe gestures to slide from one photo to another

We can add swipe gestures to any view. For example, we have a custom view over your app and we want to remove it if the user swipe from left to right. For that, we need to add a gesture recognizer to that view.

Now, we are going to apply Swipe gestures on UIView.

Let’s Start

  1. Firstly, open the main.Storyboard and add one custom View with color
  2. After that, create a outlet of a view in your ViewController file.
Swipe Gesture View

Now, Add UISwipeGestureRecognizer and create an object for swipe Gesture

Note:- A swipe gesture recognizer object monitor and perform an action only one direction, so if you want to support swiping towards two or more directions then you have to create two and more recognizer objects respectively

Note:- set UISwipeGestureRecognizer in viewDidLoad function.

Let’s Create a method that is performing an action when the UISwipeGestureRecognizer perform

Let’s run the project and check the swipe gesture, try to swipe left, right, top, down.

Conclusion :

Swipe gestures allow us to move a view to any of the four directions:- left, right, top, down. But not in a diagonal way.

I hope this blog helps you to understand the basics of UISwipeGestureRecognizer. it is very easy and simple to use and make your application interactive

Lastly, Please share your thoughts with us in the comment area.

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*

Be the first to comment.

Start a Project

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home