Skip to content

Instantly share code, notes, and snippets.

@diederikh
Last active September 14, 2015 19:43
Show Gist options
  • Save diederikh/d444ed1d61333f51bd07 to your computer and use it in GitHub Desktop.
Save diederikh/d444ed1d61333f51bd07 to your computer and use it in GitHub Desktop.
Replace child view controller segue
class ReplaceSegue: UIStoryboardSegue {
override func perform() {
let containerViewController = sourceViewController
if containerViewController.childViewControllers.count == 0 {
return;
}
let sourceVC = containerViewController.childViewControllers[0]
containerViewController.addChildViewController(destinationViewController)
destinationViewController.view.frame = sourceVC.view.frame
sourceVC.willMoveToParentViewController(nil)
containerViewController.transitionFromViewController(sourceVC, toViewController: destinationViewController, duration: 0.5, options: .TransitionCrossDissolve, animations: { () -> Void in
}, completion: { (animated) -> Void in
sourceVC.removeFromParentViewController()
self.destinationViewController.didMoveToParentViewController(containerViewController)
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment