Difference between revisions of "Swift:Using UIGestureRecognizer"

From Hawk Wiki
Jump to: navigation, search
(Created page with "==Tap gesture recognizer== <pre class="brush:swift"> func onCustomTap(tapGestureRecognizer: UITapGestureRecognizer) { var point = tapGestureRecognizer.locationInView(view)...")
 
(No difference)

Latest revision as of 17:58, 27 March 2015

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 {
            
    }
}