Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is a common problem: if you instantiate a view controller, the add its view to another view controller´s view through <code>addSubview</code>, then the first controller will not get any autorotation related called.</p> <p>To cope with this use case, Apple added to iOS5 what is called as <em><code>UIViewController</code> Containment</em>, where you can add a child controller to another controller; then all relevant methods (<code>viewWillAppear/Disappear</code>; autorotation methods etc. will be auto-routed to child controllers).</p> <p>Here are the essential methods you might need to call:</p> <pre><code>addChildViewController: removeFromParentViewController willMoveToParentViewController: didMoveToParentViewController: </code></pre> <p>Have a look at <a href="http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html" rel="nofollow">Implementing a Container View Controller</a> for detailed info.</p> <p><a href="http://www.cocoanetics.com/2012/04/containing-viewcontrollers/" rel="nofollow">Here</a> you can find a tutorial that will give you step-by-step instructions as to how to use containment.</p> <p>Keep in mind that this will only work for iOS>5, so if you need to support iOS4, you are out of luck. In any case, you might try to build a workaround by relaying the relevant messages to your sub controllers. E.g., in a app of mine, this is what <code>willAnimateRotationToInterfaceOrientation</code> and <code>didRotateFromInterfaceOrientation</code> look like:</p> <pre><code>- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration { [self.mainButtonBarController willAnimateRotationToInterfaceOrientation:interfaceOrientation duration:duration]; [self.boardController willAnimateRotationToInterfaceOrientation:interfaceOrientation duration:duration]; } - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { [self.mainButtonBarController didRotateFromInterfaceOrientation:fromInterfaceOrientation]; [self.boardController didRotateFromInterfaceOrientation:fromInterfaceOrientation]; } </code></pre> <p>I.e., they simply forward the same message to the child controllers. You can do the same for other methods you need (<code>shouldAutorotate...</code>, etc.)</p>
 

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