Skip to content

Instantly share code, notes, and snippets.

@soggybag
Created November 19, 2015 23:13
Show Gist options
  • Save soggybag/f1b4e681547b72f98d3f to your computer and use it in GitHub Desktop.
Save soggybag/f1b4e681547b72f98d3f to your computer and use it in GitHub Desktop.
Pan Gesture Drag
// Simple drag using pan UIPanGestureRecognizer
func handlePanGesture(panGesture: UIPanGestureRecognizer) {
// translation
let translation = panGesture.translationInView(view)
panGesture.setTranslation(CGPointZero, inView: view)
// DX DY
let object = panGesture.view as! UIView
var offset = object.center
object.center = CGPoint(x: object.center.x + translation.x, y: object.center.y + translation.y)
}
// Add a gesture
let pan = UIPanGestureRecognizer(target: self, action: Selector("handlePanGesture:"))
someObject.addGestureRecognizer(pan)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment