You are looking for a custom container controller.
If this is programmatic, you call addChildViewController on the parent controller (thereby adding the child view controller to the view manager hierarchy), complete the entire configuration of the child view (including adding it to the parent controller view hierarchy), and then call didMoveToParentViewController on the child:
let childController = self.storyboard?.instantiateViewControllerWithIdentifier("storyboardIdForChildScene") as UIViewController! addChildViewController(childController) childController.view.frame = ... scrollView.addSubview(childController.view) childController.didMoveToParentViewController(self)
When you delete programmatically, you cancel this process by calling willMoveToParentViewController:nil for the child, remove the child view from your supervisor, and when done, call removeFromParentViewController :
childController.willMoveToParentViewController(nil) childController.view.removeFromSuperview() childController.removeFromParentViewController()
If you do this in Interface Builder, it’s much simpler, just drag and drop the “Container View” from the “Object Library” onto the scene of the parent view controller:

For more information on how to do this, see Create Custom Container View Controllers in the View Controller Programming Guide. For a discussion of why it is important to perform these containment calls in order to maintain a view manager hierarchy synchronized with a view hierarchy, see WWDC 2011 Video Implementing the UIViewController Containment .
Rob
source share