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

3
我正在尝试在iPad上创建一个简单的模态对话框,无论是小型(UIModalPresentationFormSheet)还是较大型(UIModalPresentationPageSheet)设置,但无论我做什么,它们都会全屏显示(带有标题栏)。
模态UIViewController是在界面构建器中创建的,我似乎无法为其指定大小。为UIViewController内包含的UIView指定较小的大小没有任何效果。
我做错了什么?可能会影响这个问题的因素是什么?这可能是我设置modalPresentationStyle的时间吗?我已经尝试过使用UINavigationController和不使用,但结果相同。
2个回答

5
在调用presentModalViewController:animated之前,您必须在父视图控制器中设置modalPresentationStyle。请注意,在调用此方法之前完成此操作。
myViewController = // create your new controller if needed 
myViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
myViewController.modalPresentationStyle = UIModalPresentationFormSheet;
// "self" is the parent ViewController
[self presentModalViewController:myViewController animated:YES]

这是否意味着整个层次结构都应该是模态的?因为我理解,我的根(顶部)UIViewController 是一个普通的非模态视图。我也应该使用 presentModalViewController:animated 显示它吗? - ldoogy
不,父视图控制器可以是非模态的UIViewController。 - Felix

3

我已经弄清楚了。原来我使用的是UIModalPresentationPageSheet,它在竖屏模式下总是进入全屏模式。因为我的模态UIViewController没有响应shouldAutorotateToInterfaceOrientation,它强制使用纵向方向,这就是为什么我认为模态弹出窗口不起作用的原因。

只需在我的模态UIViewController中添加一个shouldAutorotateToInterfaceOrientation处理程序,返回YES,我现在看到在横向模式下我确实得到了一个大的弹出窗口,它覆盖了大部分屏幕(但不是全部),这正是我一直期望的。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接