Swift:Using UIGestureRecognizer

From Hawk Wiki
Jump to: navigation, search

Tap gesture recognizer

func onCustomTap(tapGestureRecognizer: UITapGestureRecognizer) {
   var point = tapGestureRecognizer.locationInView(view)

   // User tapped at the point above. Do something with that if you want.
}

UIPanGestureRecognizer

func onCustomPan(panGestureRecognizer: UIPanGestureRecognizer) {
   var point = panGestureRecognizer.locationInView(view)
   var velocity = panGestureRecognizer.velocityInView(view)

   if panGestureRecognizer.state == UIGestureRecognizerState.Began {
      println("Gesture began at: \(point)")
   } else if panGestureRecognizer.state == UIGestureRecognizerState.Changed {
      println("Gesture changed at: \(point)")
   } else if panGestureRecognizer.state == UIGestureRecognizerState.Ended {
      println("Gesture ended at: \(point)")
   }
}

UIPinchGestureRecognizer

func onCustomPinch(sender: UIPanGestureRecognizer) {
    var scale = sender.scale
    if sender.state == UIGestureRecognizerState.Began {
            
    } else if sender.state == UIGestureRecognizerState.Changed {
            
    } else if sender.state == UIGestureRecognizerState.Ended {
            
    }
}