Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>UPD: June, 2015</strong> <strong>Swift</strong></p> <p>The concept remains the same, which is described below in Objective-C section. There is a little change in syntax. To add childviewcontroller use following snippet:</p> <pre><code>let aViewController = storyboard.instantiateViewControllerWithIdentifier("A") as! AViewController; addChildViewController(aViewController); scrollView!.addSubview(aViewController.view) aViewController.didMoveToParentViewController(self) </code></pre> <p>Check my <a href="https://github.com/gneil90/CustomScrollContainer">Swift Github Sample Code</a></p> <p><strong>Objective-C</strong></p> <p>Create your own custom container view controller (I will call it combinedViewController), which will hold your three controllers in scroll view. Inherit like you always do UIViewController, then use addChildViewController public API in your new combinedViewController <code>-viewDidLoad:</code> like this:</p> <pre><code>[self addChildViewController:aViewController]; [self.scrollView addSubview:aViewController.view]; [aViewController didMoveToParentViewController:self]; </code></pre> <p>Here’s what the code does:</p> <ul> <li>It calls the container’s addChildViewController: method to add the child.</li> <li>It accesses the child’s view property to retrieve the view and adds it to its own view hierarchy. The container sets the child’s size and position before adding the view; containers always choose where the child’s content appears.</li> <li>It explicitly calls the child’s didMoveToParentViewController: method to signal that the operation is complete.</li> </ul> <p>Do this operation with each of your viewControllers. Afterwards, set your combinedViewController as a rootViewController. </p> <p>if you need further explanation, feel free to ask.</p> <p>Reference: <a href="https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/CreatingCustomContainerViewControllers/CreatingCustomContainerViewControllers.html#//apple_ref/doc/uid/TP40007457-CH18-SW6">Design custom container view controller</a></p> <p>Here you are my <a href="https://github.com/gneil90/CustomContainerViewController">Objective-C Github sample code</a></p> <p><strong>UPD:</strong> Thanks @Oliver Atkinson for clarifying that <code>addChildViewController:</code> method also calls the child’s <code>willMoveToParentViewController:</code> method automatically. </p> <p><strong>Results:</strong></p> <p><a href="https://i.stack.imgur.com/PrjPZ.gif"><img src="https://i.stack.imgur.com/PrjPZ.gif" alt="enter image description here"></a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload