【问题标题】:Modal UIViewController always coming out full screen on iPad. WHY?模态 UIViewController 总是在 iPad 上全屏显示。为什么?
【发布时间】:2011-01-12 18:11:24
【问题描述】:

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

模态 UIViewController 是在界面构建器中创建的,我似乎无法为其指定大小。为 UIViewController 中包含的 UIView 指定较小的尺寸无效。

我做错了什么?什么可能会影响这个问题?可能是我设置 modalPresentationStyle 的时间吗?我尝试过使用 UINavigationController 和不使用 UINavigationController,但得到了相同的结果。

【问题讨论】:

    标签: iphone ios uiviewcontroller


    【解决方案1】:

    在调用presentModalViewController:animated之前你必须在父ViewController中设置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 来展示那个吗?
    • 不,父级可以是非模态 UIViewController。
    【解决方案2】:

    我已经想通了。原来我使用的是 UIModalPresentationPageSheet,它总是会在纵向模式中全屏显示。因为我的模态 UIViewController 没有响应 shouldAutorotateToInterfaceOrientation,所以它强制为纵向,这就是我认为模态弹出窗口不起作用的原因。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多