Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. // define a variable to store initial touch position
  2. var initialTouchPoint: CGPoint = CGPoint(x: 0,y: 0)
  3.  
  4. @IBAction func panGestureRecognizerHandler(_ sender: UIPanGestureRecognizer) {
  5. let touchPoint = sender.location(in: self.view?.window)
  6.  
  7. if sender.state == UIGestureRecognizerState.began {
  8. initialTouchPoint = touchPoint
  9. } else if sender.state == UIGestureRecognizerState.changed {
  10. if touchPoint.y - initialTouchPoint.y > 0 {
  11. self.view.frame = CGRect(x: 0, y: touchPoint.y - initialTouchPoint.y, width: self.view.frame.size.width, height: self.view.frame.size.height)
  12. }
  13. } else if sender.state == UIGestureRecognizerState.ended || sender.state == UIGestureRecognizerState.cancelled {
  14. if touchPoint.y - initialTouchPoint.y > 100 {
  15. self.dismiss(animated: true, completion: nil)
  16. } else {
  17. UIView.animate(withDuration: 0.3, animations: {
  18. self.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height)
  19. })
  20. }
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement