3

我有一个 iPad 应用程序,它有一个UITabBarController作为根控制器。从其中一个选项卡中,我有一个UIToolBar包含一个UIBarButtonItem,单击时会启动一个模态视图。

首次启动时(横向和纵向)模态视图以正确的大小显示,但是如果您旋转设备,则模态视图将扩展以填满屏幕 - 无论您从该点开始旋转设备多少。

我正在从标签栏启动模态视图,并且我已经ModalPresentationStyle在要呈现的视图中设置了。

无论我将其设置为FormSheet还是,这都会影响 ModalView PageSheet

有没有人遇到过类似的行为,如果有,您是如何解决的?

非常感谢

编辑

我还注意到,自 4.2 以来,当使用模态样式页面/表单表时,模态视图后面的视图不再变暗 - 我呈现的视图是错误的,还是这只是 4.2 的标准?

编辑 2

代码:在我的默认情况下UIViewController,我只是简单地呈现模态视图,如下所示:

void HandleNewMsgButtonTouch(object sender, EventArgs e)
{
   PresentModalViewController(new ComposeMsgView(), true);
}

在模态视图本身中,我在LoadView覆盖中指定:

public override void LoadView()
{
   base.LoadView ();
   ...
   // initialser code related to the view
   ...
   View.AutoresizingMask = UIViewAutoresizing.None;
   ModalPresentationStyle = UIModalPresentationStyle.PageSheet;
   ModalTransitionStyle = UIModalTransitionStyle.CrossDissolve;
}

我也覆盖了ShouldAutoRotateToInterfaceOrientation始终返回 true 。

无论我是否使用 Formsheet / Pagesheet,它们在首次启动时都会显示正确的宽度(无论是横向还是纵向 - 我知道 PageSheet 将填充纵向视图)但是在旋转时,模态视图将填充屏幕(如如果我用 FullScreen 呈现 ModalView)。

4

3 回答 3

4

As stated in the comment, try this:

void HandleNewMsgButtonTouch(object sender, EventArgs e)
{
    UIViewController oController = new ComposeMsgView();
    oController.ModalPresentationStyle = UIModalPresentationStyle.PageSheet;
    PresentModalViewController(oController, true);
}

LoadView() is too late to set the properties.

Previous content: Please post some code. The view is definitely dimmed, also in 4.2. I assume that you are setting the presentation style on the wrong controller, because "PageSheet" is transformed to fullscreen when in portrait mode.

You have to set the presentation style on the controller you want to show in the moda view and not on the one which IS showing. So if your controller to show is "oToShow" and the one you are showing from is "oCurrent", you would have to set the style for "oToShow". Try setting it to FormSheet which will always be on top and never goes fullscreen.

René

于 2011-01-15T06:56:45.817 回答
1

你可以通过使用不同的风格来解决它,比如

UIModalPresentationFullScreen:这是默认样式,顾名思义,会导致模态视图像 iPhone 一样全屏显示

UIModalPresentationPageSheet:模态视图占据全屏高度,但宽度设置为纵向模式下的屏幕宽度。这意味着当设备处于纵向模式时,它仍然占据全屏。然而,在横向模式下,它使一些底层主视图仍然可见,但由于用户无法与未覆盖的主视图控制器交互而变暗。

UIModalPresentationFormSheet:模态视图的宽度和高度都设置为小于屏幕尺寸。模态视图位于屏幕中心,主视图控制器的未覆盖区域变暗以防止用户交互。如果模态视图使用键盘,则模态视图向上移动以腾出空间。

UIModalPresentationCurrentContext:模态视图使用与父主视图控制器相同的样式显示。

还要记住调整大小和位置,否则它将始终以 PageFormSheet 的默认大小显示。

希望这有助于亚历克斯

于 2011-01-13T18:26:34.090 回答
0
View.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
于 2010-12-21T16:33:59.587 回答