问题
I am trying to create a simple modal dialog on the iPad, in either the small (UIModalPresentationFormSheet) or the larger (UIModalPresentationPageSheet) settings, but they come out full screen (with a title bar) no matter what I do.
The modal UIViewController was created in interface builder where I can't seem to specify a size for it. Specifying a smaller size for the UIView contained within the UIViewController has no effect.
What am I doing wrong? What would possibly affect this issue? Could it be the timing in which I am setting modalPresentationStyle? I have tried both using a UINavigationController and without, but am getting the same result.
回答1:
You must set modalPresentationStyle
in the parent ViewController before calling presentModalViewController:animated
.
myViewController = // create your new controller if needed
myViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
myViewController.modalPresentationStyle = UIModalPresentationFormSheet;
// "self" is the parent ViewController
[self presentModalViewController:myViewController animated:YES]
回答2:
I've figured this out. Turns out I was using UIModalPresentationPageSheet, which always goes to full screen in portrait mode. Because my modal UIViewController wasn't responding to shouldAutorotateToInterfaceOrientation, it was forcing a portrait orientation, which is why I THOUGHT the modal popup wasn't working.
By simply adding a shouldAutorotateToInterfaceOrientation handler to my modal UIViewController, that returns YES, I now see that in landscape mode I am getting a large popup that covers most (but not all) of the screen, which is what I've been expecting.
来源:https://stackoverflow.com/questions/4672314/modal-uiviewcontroller-always-coming-out-full-screen-on-ipad-why