Last active
September 14, 2015 19:43
-
-
Save diederikh/d444ed1d61333f51bd07 to your computer and use it in GitHub Desktop.
Replace child view controller segue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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