Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // define a variable to store initial touch position
- var initialTouchPoint: CGPoint = CGPoint(x: 0,y: 0)
- @IBAction func panGestureRecognizerHandler(_ sender: UIPanGestureRecognizer) {
- let touchPoint = sender.location(in: self.view?.window)
- if sender.state == UIGestureRecognizerState.began {
- initialTouchPoint = touchPoint
- } else if sender.state == UIGestureRecognizerState.changed {
- if touchPoint.y - initialTouchPoint.y > 0 {
- self.view.frame = CGRect(x: 0, y: touchPoint.y - initialTouchPoint.y, width: self.view.frame.size.width, height: self.view.frame.size.height)
- }
- } else if sender.state == UIGestureRecognizerState.ended || sender.state == UIGestureRecognizerState.cancelled {
- if touchPoint.y - initialTouchPoint.y > 100 {
- self.dismiss(animated: true, completion: nil)
- } else {
- UIView.animate(withDuration: 0.3, animations: {
- self.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height)
- })
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement