Last active
January 18, 2018 18:43
-
-
Save yingmu52/5c8db4831618c9bac00d8911f781e724 to your computer and use it in GitHub Desktop.
Code Snippets
This file contains 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
func panGestureAction(_ panGesture: UIPanGestureRecognizer) { | |
let translation = panGesture.translation(in: view) | |
if panGesture.state == .began { | |
originalPosition = view.center | |
originalPositionNC = navigationController?.navigationBar.center | |
currentPositionTouched = panGesture.location(in: view) | |
} else if panGesture.state == .changed { | |
if (translation.y > 0){ | |
view.frame.origin = CGPoint( | |
x: view.frame.origin.x, | |
y: view.frame.origin.y + translation.y | |
) | |
self.navigationController?.navigationBar.frame.origin = CGPoint( | |
x: self.view.frame.origin.x, | |
y: view.frame.origin.y + translation.y | |
) | |
panGesture.setTranslation(CGPoint.zero, in: self.view) | |
} | |
} else if panGesture.state == .ended { | |
let velocity = panGesture.velocity(in: view) | |
if velocity.y >= 150 { | |
UIView.animate(withDuration: 0.2 | |
, animations: { | |
self.view.frame.origin = CGPoint( | |
x: self.view.frame.origin.x, | |
y: self.view.frame.size.height | |
) | |
self.navigationController?.navigationBar.frame.origin = CGPoint( | |
x: self.view.frame.origin.x, | |
y: self.view.frame.size.height | |
) | |
}, completion: { (isCompleted) in | |
if isCompleted { | |
self.dismiss(animated: false, completion: nil) | |
} | |
}) | |
} else { | |
UIView.animate(withDuration: 0.2, animations: { | |
self.view.center = self.originalPosition! | |
self.navigationController?.navigationBar.center = self.originalPositionNC | |
}) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment