Swipe to go back

I’ve finished the CustomLoginDemo and I wanted to add the ability to go back from the SignInViewControler to the Root View Controller.

I’ve added a Swipe Gesture Recognizer and implemented that into my SignInViewcontroller with the action func ‘swipeRight’.

I’m not quite sure how to implement the transition from the SignInViewController back to the view controller with a swipe right along with the corresponding animation.

I’ve done it with the standard ‘show’ before, however, the animation is the opposite of what I’m looking for - swiping right scrolls the root view controller in from the right instead of the left, which looks more natural.

Any idea how to switch this segue animation? I’ve Googled and Youtubed for hours to no avail, along with searching these forums.

EDIT: Upon further review, it looks like I’ll have to create a custom segue and use that?

You should embed your first VC into a navigation controller

This video may help you understand what this is https://youtu.be/LbAd2FIlnos

The first VC is linked to a navigation controller as per the early instructions in the CustomLoginDemo video. I’m able to navigate forward from the Login/Signup page (root view controller) to the SignUpViewController, however, I can’t go back with the correct animation. I’d like to add the ability to swipe back with the correct segue animation.

As I said in my post, I’m able to swipe and return, it’s the segue animation that’s incorrect.

Thank you for your reply!

I’ve finally found the solution!

It was as simple as I was searching and hoping for as well.

I ended up using an unwind segue to avoid stacking the View Controllers by simply adding a custom segue on a swipe transition.

First I created the unwind function in the destination View Controller (Root View Controller)

**@IBAction** **func** unwind( **_** seg: UIStoryboardSegue) {

Then I headed over to my Story Board and CTRL + Dragged the View Controller (in documents outline) to the ‘Exit’ object and selected unwind: segue, naming it ‘unwindToRootVC’.

Then I went back to the Origin View Controller class and wrote out the action function to perform the unwind segue which I then implemented within the Swipe Gesture Action function which follows it.

**@IBAction** **func** backToRootVC( **_** sender: **Any** ) {

performSegue(withIdentifier: "unwindToRootVC", sender: **self** )


**@IBAction** **func** swipeRight( **_** sender: **Any** ) {

backToRootVC(( **Any** ). **self** )