Modal UIViewController总是在iPad上全屏显示。 为什么?

我试图在iPad(UIModalPresentationFormSheet)或较大的(UIModalPresentationPageSheet)设置上创build一个简单的模式对话框,但是无论我做什么,它们都会全屏显示(带有标题栏)。

模式UIViewController是在界面生成器中创build的,我似乎无法为其指定大小。 为UIViewController中包含的UIView指定较小的大小没有任何影响。

我究竟做错了什么? 什么可能会影响这个问题? 难道是我设置modalPresentationStyle的时机? 我已经尝试使用UINavigationController和没有,但获得相同的结果。

调用presentModalViewController:animated 之前,必须在父ViewController中设置modalPresentationStyle 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] 

我已经明白了这一点。 原来我使用的是UIModalPresentationPageSheet,它总是以纵向模式全屏显示。 因为我的模态UIViewController没有响应shouldAutorotateToInterfaceOrientation,这是强制纵向,这就是为什么我想模态popup不工作。

通过简单地添加一个shouldAutorotateToInterfaceOrientation处理程序到我的模态UIViewController,返回YES,我现在看到,在横向模式下,我得到一个大的popup窗口,涵盖了大多数(但不是全部)的屏幕,这是我一直期待的。