Swift to achieve click double click pinch rotation drag stroke long press gesture class and method

  • 2020-05-06 11:43:20
  • OfStack

1.UITapGestureRecognizer click/double click gesture


var tapGesture = UITapGestureRecognizer(target: self, action: "handleTapGesture:") 
// Set the number of gesture clicks , Double-click: point 2 Under the  
tapGesture.numberOfTapsRequired = 2 
self.view.addGestureRecognizer(tapGesture)

2.UIPinchGestureRecognizer pinch (zoom in/out) gesture

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

3.UIRotationGestureRecognizer rotating gesture

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

4. UIPanGestureRecognizer drag gesture

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

5. UISwipeGestureRecognizer swipes

var swipeGesture = UISwipeGestureRecognizer(target: self, action: "handleSwipeGesture:") 
swipeGesture.direction = UISwipeGestureRecognizerDirection.Left // No, it's right  
self.view.addGestureRecognizer(swipeGesture)

6. UILongPressGestureRecognizer long gesture

   var longpressGesutre = UILongPressGestureRecognizer(target: self, action: "handleLongpressGesture:") 
    // According to time long  
    // longpressGesutre.minimumPressDuration
    // Required number of touches
    /// longpressGesutre.numberOfTouchesRequired 
    self.view.addGestureRecognizer(longpressGesutre) 
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
}


Related articles: