Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 238
Julie Avatar asked Aug 22 '26 12:08

Julie


1 Answers

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


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!