Search code examples
ipadiphone-sdk-3.0modal-dialogshowmodaldialog

Modal View using UIModalPresentationFormSheet appears offscreen


I have a UIViewController that implements

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

Then, I try to popup a modal on top of that view:

ModalViewController *modalViewController = [[ModalViewController alloc] init];
modalViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
modalViewController.modalPresentationStyle = UIModalPresentationFormSheet;
[mainViewController presentModalViewController:modalViewController animated:YES]; 

If I launch the modal while the ipad is in portrait, it works fine. But when I'm holding it in landscape and try to launch the modal, the modal appears half offscreen to the upper right of the ipad. Any ideas?


Solution

  • In ModalViewController, implement shouldAutorotateToInterfaceOrientation the same way that it is in mainViewController (both need to agree on the orientations they support).