Guest User

Untitled

a guest
May 23rd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. class ViewController: UIViewController {
  2.  
  3. override func viewDidLoad() {
  4. super.viewDidLoad()
  5. modalPresentationStyle = .overFullScreen
  6. view.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(panGestureRecognizerHandler)))
  7. }
  8.  
  9. @objc func panGestureRecognizerHandler(_ gesture: UIPanGestureRecognizer) {
  10. let translation = gesture.translation(in: view)
  11.  
  12. view.frame.origin = translation
  13.  
  14. if gesture.state == .ended {
  15. let velocity = gesture.velocity(in: view)
  16.  
  17. if velocity.y >= 1500 {
  18. self.dismiss(animated: true)
  19. } else {
  20. UIView.animate(withDuration: 0.3, animations: {
  21. self.view.frame.origin = CGPoint.zero
  22. })
  23. }
  24. }
  25. }
  26. }
Add Comment
Please, Sign In to add comment