Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ViewController: UIViewController {
- override func viewDidLoad() {
- super.viewDidLoad()
- modalPresentationStyle = .overFullScreen
- view.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(panGestureRecognizerHandler)))
- }
- @objc func panGestureRecognizerHandler(_ gesture: UIPanGestureRecognizer) {
- let translation = gesture.translation(in: view)
- view.frame.origin = translation
- if gesture.state == .ended {
- let velocity = gesture.velocity(in: view)
- if velocity.y >= 1500 {
- self.dismiss(animated: true)
- } else {
- UIView.animate(withDuration: 0.3, animations: {
- self.view.frame.origin = CGPoint.zero
- })
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment