The simplest way I found is to create custom Segue.
Creating custom UIStoryboardSegue
- Go to File -> New -> File... and choose Cocoa Class
- Create a new class from UIStoryboardSegue
- Configurate MySegue
import UIKit
class NewSegue: UIStoryboardSegue {
//Call when performSegueWithIdentifier() called
override func perform() {
//ViewController segue FROM
var sourceViewController: UIViewController = self.sourceViewController as! UIViewController
//ViewController segue TO
var destinationViewController: UIViewController = self.destinationViewController as! UIViewController
//Parent ViewController - ContainerViewController
var containerViewController: UIViewController = sourceViewController.parentViewController!
//Setting destinationViewController
containerViewController.addChildViewController(destinationViewController)
destinationViewController.view.frame = sourceViewController.view.frame
sourceViewController.willMoveToParentViewController(nil)
//Do animation
containerViewController.transitionFromViewController(sourceViewController,
toViewController: destinationViewController,
duration: 0.3,
options: UIViewAnimationOptions.TransitionCrossDissolve,
animations: nil, completion: { finished in
//Delete sourceViewController
sourceViewController.removeFromParentViewController()
//Show destinationViewController
destinationViewController.didMoveToParentViewController(containerViewController)
})
}
}
- Go to your Storyboard file and do control drag from ContainerViewController to needed Controller and choose Custom in context menu
3.Click on created segue and configure them
- Now you can call
performSegueWithIdentifier("SugueID", sender: self)
in your ContainerViewController or in other ViewController