SoFunction
Updated on 2025-03-02

Introduction to the classes and methods for clicking, double-clicking, pinching, rotating, dragging, swinging, and long-pressing gestures in Swift

Click/Double-tap gesture

Copy the codeThe code is as follows:

var tapGesture = UITapGestureRecognizer(target: self, action: "handleTapGesture:") 
//Set the number of clicks on the gesture, double-click: click 2
= 2 
(tapGesture)

Pinch (zoom in/out) gesture
Copy the codeThe code is as follows:

var pinchGesture = UIPinchGestureRecognizer(target: self, action: "handlePinchGesture:") 
(pinchGesture)

Rotate gesture
Copy the codeThe code is as follows:

var rotateGesture = UIRotationGestureRecognizer(target: self, action: "handleRotateGesture:") 
 (rotateGesture) 

4. UIPanGestureRecognizer drag gesture
Copy the codeThe code is as follows:

 var panGesture = UIPanGestureRecognizer(target: self, action: "handlePanGesture:") 
 (panGesture) 

5. UISwipeGestureRecognizer Stroke gesture
Copy the codeThe code is as follows:

var swipeGesture = UISwipeGestureRecognizer(target: self, action: "handleSwipeGesture:") 
= //Not set is right
(swipeGesture)

6. UILongPressGestureRecognizer Long press gesture
Copy the codeThe code is as follows:

   var longpressGesutre = UILongPressGestureRecognizer(target: self, action: "handleLongpressGesture:") 
//Press for a long time
    //
//Number of touches required
    ///  
    (longpressGesutre) 
The UIGestureRecognizerState enumeration is defined as follows

enum UIGestureRecognizerState : Int {

    case Possible // the recognizer has not yet recognized its gesture, but may be evaluating touch events. this is the default state

    case Began // the recognizer has received touches recognized as the gesture. the action method will be called at the next turn of the run loop
    case Changed // the recognizer has received touches recognized as a change to the gesture. the action method will be called at the next turn of the run loop
    case Ended // the recognizer has received touches recognized as the end of the gesture. the action method will be called at the next turn of the run loop and the recognizer will be reset to UIGestureRecognizerStatePossible
    case Cancelled // the recognizer has received touches resulting in the cancellation of the gesture. the action method will be called at the next turn of the run loop. the recognizer will be reset to UIGestureRecognizerStatePossible

    case Failed // the recognizer has received a touch sequence that can not be recognized as the gesture. the action method will not be called and the recognizer will be reset to UIGestureRecognizerStatePossible
}