Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unpinch custom gesture recognizer with three fingers in iOS

I want to make a custom gesture recognizer with three fingers. Which is similar to unpinch gesture recognizer.

All I need is an idea about how to recognize it.

My gesture needs to recognize three fingers with three directions. For example:

enter image description here

enter image description here

enter image description here

I hope images makes sense. I need to make it flexible for any three opposite directions. Thanks in advance. Any help would be appreciated.

I am aware about the subclass methods and I've created custom gestures already with single finger like semicircle, full circle. I need a coding idea about how to handle that.

like image 650
Dinesh Raja Avatar asked May 11 '14 10:05

Dinesh Raja


People also ask

How do you turn off three finger gestures on IOS 14?

Unfortunately, you can't disable three fingers gestures but you can use AssistiveTouch. Please Go to Settings > Accessibility > Touch > AssistiveTouch, then turn on AssistiveTouch. Then you see a button appear onscreen and You can drag the button to any edge of the screen.

What is pinch gesture on Iphone?

Overview. A pinch gesture is a continuous gesture that tracks the distance between the first two fingers that touch the screen. Use the UIPinchGestureRecognizer class to detect pinch gestures. You can attach a gesture recognizer in one of these ways: Programmatically.

What is UITapGestureRecognizer Swift?

UITapGestureRecognizer is a concrete subclass of UIGestureRecognizer . For gesture recognition, the specified number of fingers must tap the view a specified number of times. Although taps are discrete gestures, they're discrete for each state of the gesture recognizer.


1 Answers

You need to create a UIGestureRecognizer subclass of your own (let's call it DRThreeFingerPinchGestureRecognizer) and in it to implement:

– touchesBegan:withEvent:
– touchesMoved:withEvent:
– touchesEnded:withEvent:
– touchesCancelled:withEvent:

These methods are called when touches are accepted by the system and possibly before they are sent to the view itself (depending on how you setup the gesture recognizer). Each of these methods will give you a set of touches, for which you can check the current location in your view and previous location. Since pinch gesture is relatively very simple, this information is enough for you to test if the user is performing a pinch, and fail the test (UIGestureRecognizerStateFailed). If state was not failed by – touchesEnded:withEvent:, you can recognize the gesture.

I say pinch gestures are simple, because you can easily track each touch and see how it moves compared to other touches and itself. If a threshold of an angle is passed and broken, you fail the test, otherwise you allow it to continue. If touches do not move in separate angles to each other, you fail the test. You will have to play with what angles of the vectors are acceptable, because 120 degrees are not optimal for the three most common fingers (thumb + index + middle fingers). You may just want to check that the vectors are not colliding.

Make sure to read the UIGestureRecognizer documentation for an in-depth look at the various methods, as well as subclassing notes.

like image 166
Léo Natan Avatar answered Oct 16 '22 23:10

Léo Natan