title: iOS 6: Parent modal's modalPresentationStyle ignored after rotation
body: <p>With iPad with iOS6, we have this bug where a modal view controller will expand to full screen, even if it is told to 
  be using "form sheet" presentation style.  But, this happens only if there are two modals, a parent one and its child.</p>
  
  <p>So this is how the first modal is created and presented:</p>
  
  <pre><code>UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:controller] autorelease];
  navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
  [parentController presentModalViewController:navigationController animated:YES];
  // parentController is my application's root controller
  </code></pre>
  
  <p>This is how the child modal is created and presented:</p>
  
  <pre><code>UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:controller] autorelease];
  navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
  [parentController presentModalViewController:navigationController animated:YES];
  // parentController is the navigationController from above
  </code></pre>
  
  <p>So when rotating from landscape to portrait, the parent modal will expand to full screen and remain that way even if we rotate back to landscape.</p>
  
  <p>When we have the parent modal all by itself (no child modal), then it works as expected, which is that it remains in form sheet style.</p>
  
  <p>Note that this happens on iOS6 only (device and simulator) and doesn't happen on iOS 5 (simulator and reported to work by testers).</p>
  
  <p>So far, I have tried the following without success:</p>
  
  <ul>
  <li>setting <code>wantsFullScreenLayout</code> to <code>NO</code></li>
  <li>forcing <code>wantsFullScreenLayout</code> to always return <code>NO</code> by overriding it</li>
  <li>Making certain my controllers inside the navigation controller also specify <code>UIModalPresentationFormSheet</code></li>
  <li>implementing <code>preferredInterfaceOrientationForPresentation</code></li>
  <li>upgrade to iOS 6.0.1</li>
  </ul>
  
  <p>Thanks!</p>
  
  <hr>
  
  <p><strong>UPDATE</strong>:
  So, I adapted the response from the Apple Developer Forums (<a href="https://devforums.apple.com/message/748486#748486" rel="noreferrer">https://devforums.apple.com/message/748486#748486</a>) so that it works with multiple nested modal.</p>
  
  <pre><code>- (BOOL) needNestedModalHack {
      return [UIDevice currentDevice].systemVersion.floatValue &gt;= 6;
  }
  
  - (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
                                            duration:(NSTimeInterval)duration {
  
      // We are the top modal, make to sure that parent modals use our size
      if (self.needNestedModalHack &amp;&amp; self.presentedViewController == nil &amp;&amp; self.presentingViewController) {
          for (UIViewController* parent = self.presentingViewController;
               parent.presentingViewController;
               parent = parent.presentingViewController) {
              parent.view.superview.frame = parent.presentedViewController.view.superview.frame;
          }
      }
  
      [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
  }
  
  - (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
                                   duration:(NSTimeInterval)duration {
      // We are the top modal, make to sure that parent modals are hidden during transition
      if (self.needNestedModalHack &amp;&amp; self.presentedViewController == nil &amp;&amp; self.presentingViewController) {
          for (UIViewController* parent = self.presentingViewController;
               parent.presentingViewController;
               parent = parent.presentingViewController) {
              parent.view.superview.hidden = YES;
          }
      }
  
      [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
  }
  
  - (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
      // We are the top modal, make to sure that parent modals are shown after animation
      if (self.needNestedModalHack &amp;&amp; self.presentedViewController == nil &amp;&amp; self.presentingViewController) {
          for (UIViewController* parent = self.presentingViewController;
               parent.presentingViewController;
               parent = parent.presentingViewController) {
              parent.view.superview.hidden = NO;
          }
      }
  
      [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
  }
  </code></pre>