Skip to content

Instantly share code, notes, and snippets.

@marcboeren
Created March 19, 2015 20:02
Show Gist options
  • Save marcboeren/165ed7de30178acfdad4 to your computer and use it in GitHub Desktop.
Save marcboeren/165ed7de30178acfdad4 to your computer and use it in GitHub Desktop.

Revisions

  1. marcboeren revised this gist Mar 19, 2015. 3 changed files with 0 additions and 0 deletions.
    File renamed without changes.
    File renamed without changes.
  2. marcboeren created this gist Mar 19, 2015.
    17 changes: 17 additions & 0 deletions MainViewController.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@

    @IBAction func segueToMe(segue: UIStoryboardSegue) {
    // segue back
    }

    override func segueForUnwindingToViewController(toViewController: UIViewController, fromViewController: UIViewController, identifier: String?) -> UIStoryboardSegue {

    if let id = identifier {
    if id == "returnToMainViewController" {
    let unwindSegue = UIStoryboardUnwindSegueFromRight(identifier: id, source: fromViewController, destination: toViewController)
    return unwindSegue
    }
    }

    return super.segueForUnwindingToViewController(toViewController, fromViewController: fromViewController, identifier: identifier)
    }

    47 changes: 47 additions & 0 deletions UIStoryboardSegueFromRight.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    import UIKit

    class UIStoryboardSegueFromRight: UIStoryboardSegue {

    override func perform()
    {
    let src = self.sourceViewController as UIViewController
    let dst = self.destinationViewController as UIViewController

    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)
    }
    )
    }
    }

    class UIStoryboardUnwindSegueFromRight: UIStoryboardSegue {

    override func perform()
    {
    let src = self.sourceViewController as UIViewController
    let dst = self.destinationViewController as UIViewController

    src.view.superview?.insertSubview(dst.view, belowSubview: src.view)
    src.view.transform = CGAffineTransformMakeTranslation(0, 0)

    UIView.animateWithDuration(0.25,
    delay: 0.0,
    options: UIViewAnimationOptions.CurveEaseInOut,
    animations: {
    src.view.transform = CGAffineTransformMakeTranslation(src.view.frame.size.width, 0)
    },
    completion: { finished in
    src.dismissViewControllerAnimated(false, completion: nil)
    }
    )
    }
    }
    3 changes: 3 additions & 0 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    Assign the class UIStoryboardSegueFromRight to the custom segue in the storyboard.

    To create an Unwind Segue, you'll need the code below in the first controller. You'll use the segueToMe to connect to the Exit in the second controller. Give that Unwind segue the identifier e.g. "returnToMainViewController".