I’m currently working on a fitness app that requires me to dismiss a View Controller by dragging down the View Controller. Most solutions online overcomplicated this task. Here is my simple solution using PanGestureRecognizerCGAffineTransform, and UIView.Animate.

You should theoretically be able to just copy and paste the code, but I’ll also include detailed explanations underneath the code snippets.

This will all take place in the ViewController in which you want to implement this solution.

1) Add addGestureRecognizer to View

We’ll first add a PanGestureRecognizer to the view of the View Controller.

override func viewDidLoad() {
	    super.viewDidLoad()
	    view.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(handleDismiss)))
	}

Add gestureRecognizer in your View Controller

The addGestureRecognizer will take an argument of UIPanGestureRecognizer with the target being self and action #selector(handleDimiss).

#mobile #swift #programming #xcode #ios

A Simple Drag Dismiss on Presented ViewController Tutorial
4.00 GEEK