Skip to content

Instantly share code, notes, and snippets.

@pingzh
Last active May 27, 2016 02:33
Show Gist options
  • Save pingzh/924d67119351f513ebe8 to your computer and use it in GitHub Desktop.
Save pingzh/924d67119351f513ebe8 to your computer and use it in GitHub Desktop.
func onPanGesture(sender: UIPanGestureRecognizer) {
let translation = sender.translationInView(view)
let velocity = sender.velocityInView(view)
if sender.state == UIGestureRecognizerState.Began {
}
else if sender.state == UIGestureRecognizerState.Changed {
contentView.snp_updateConstraints(closure: { (make) -> Void in
make.left.equalTo(view).offset(translation.x)
})
}
else if sender.state == UIGestureRecognizerState.Ended {
UIView.animateWithDuration(0.3, animations: {
if velocity.x > 0 {
self.contentView.snp_updateConstraints(closure: { (make) -> Void in
make.left.equalTo(self.view).offset(TWMenuWidth)
})
}
else {
self.contentView.snp_updateConstraints(closure: { (make) -> Void in
make.left.equalTo(self.view).offset(0)
})
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment