Skip to content

Instantly share code, notes, and snippets.

@ajonno
Last active July 3, 2016 04:15
Show Gist options
  • Save ajonno/050baa6f7d07d6277286476eba03a539 to your computer and use it in GitHub Desktop.
Save ajonno/050baa6f7d07d6277286476eba03a539 to your computer and use it in GitHub Desktop.
Custom Segue (left-right ; right-left)
//create a custom segue on storyboard between two ***UIViewControllers*** (ie. this example doesn’t need a navigation controller)
//use the class below as the custom segue class.
//use your own identifier eg. “customSegue”)
class CustomSegue: UIStoryboardSegue {
override func perform() {
let src = self.sourceViewController
let dst = self.destinationViewController
src.view.superview?.insertSubview(dst.view, aboveSubview: src.view)
//for left to right transition
//dst.view.transform = CGAffineTransformMakeTranslation(-src.view.frame.size.width, 0)
//for right to left transition (same as a Push segue)
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)
}
)
}
}
//in the source view controller you trigger the segue -> below is an example of executing a segue from a button tap Action..
@IBAction func performSegue(sender: UIButton) {
self.performSegueWithIdentifier("customSegueId", sender: self)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment