Created
November 19, 2015 23:13
-
-
Save soggybag/f1b4e681547b72f98d3f to your computer and use it in GitHub Desktop.
Pan Gesture Drag
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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