Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Slide Segue - Xcode 8.0 Swift 3.0

What is the best way to create a custom segue that lets me press a button and then a view controller slides on. I have created a left to right segue but I want to make it go the other way. I have looked at some Youtube videos and this question but they don't show me what I want.

My code:

import UIKit

class SegueFromLeft: UIStoryboardSegue
{
    override func perform()
    {
        let src = self.sourceViewController
        let dst = self.destinationViewController

        src.view.superview?.insertSubview(dst.view, aboveSubview: src.view)
        dst.view.transform = CGAffineTransformMakeTranslation(-src.view.frame.size.width, 0)

        UIView.animateWithDuration(0.25,
            delay: 0.0,
            options: UIViewAnimationOptions.CurveEaseInOut,
            animations: {
                dst.view.transform = CGAffineTransformMakeTranslation(0, 0)
            },
            completion: { finished in
                src.presentViewController(dst, animated: false, completion: nil)
            }
        )
    }
}

Basically, I want to create a segue that goes from right to left.

Thanks

I am using Xcode 8.0 and Swift 3.0

like image 495
D. Murphy Avatar asked Nov 16 '25 11:11

D. Murphy


1 Answers

Try this:

class SegueFromLeft: UIStoryboardSegue{
    override func perform(){
        let src=sourceViewController
        let dst=destinationViewController
        let slide_view=destinationViewController.view

        src.view.addSubview(slide_view)
        slide_view.transform=CGAffineTransform.init(translationX: src.view.frame.size.width, 0)

        UIView.animateWithDuration(0.25,
            delay: 0.0,
            options: UIViewAnimationOptions.CurveEaseInOut,
            animations: {
                slide_view.transform=CGAffineTransform.identity
        }, completion: {finished in
                src.present(dst, animated: false, completion: nil)
                slide_view.removeFromSuperview()
        })
    }
}
like image 170
Marie Dm Avatar answered Nov 19 '25 05:11

Marie Dm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!