iPad FormSheet/PageSheet 模态视图,旋转时填充整个屏幕。T
我有一个 iPad 应用程序,它有一个 UITabBarController 作为根控制器。在其中一个选项卡中,我有一个 UIToolBar
,其中包含一个 UIBarButtonItem
,单击时会启动模态视图。
首次启动时,模式视图以正确的尺寸显示(横向和纵向),但是如果您旋转设备,模式视图将扩展以填充屏幕 - 无论您从该点开始旋转设备多少。
我从选项卡栏启动模态视图,并在要呈现的视图中设置了 ModalPresentationStyle
。
无论我将 ModalView 设置为 FormSheet
还是 PageSheet
,这都会影响 ModalView。
有没有人经历过类似的行为,如果有,你是如何解决的?
非常感谢
编辑
我还注意到,从 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 将填充纵向视图),但是在旋转时,模式视图将填充屏幕(如如果我用全屏呈现 ModalView)。
I have a iPad application, which has a UITabBarController
as the root controller. From one of the tabs, I have a UIToolBar
which contains a UIBarButtonItem
, when clicked launches a Modal View.
The modal view appears in the correct size when first launched (in both landscape and portrait) however if you rotate the device, the modal view will then expand to fill the screen - regardless of how much you rotate the device from that point onwards.
I'm launching the modal view from the tab bar and I've set the ModalPresentationStyle
in the view to be presented.
This affects the ModalView regardless of whether I set it to FormSheet
or PageSheet
.
Has anyone experienced similar behaviour, if so, how did you solve it?
Many thanks
EDIT
I've also noticed that since 4.2 when using a Modal Style Page/FormSheet that the view behind the Modal View isn't dimmed out anymore - am I presenting the view wrong or is this just standard on 4.2?
EDIT 2
Code:
In my default UIViewController
I simply present the Modal view as follows:
void HandleNewMsgButtonTouch(object sender, EventArgs e)
{
PresentModalViewController(new ComposeMsgView(), true);
}
In the modal view itself, I've specified in the LoadView
override:
public override void LoadView()
{
base.LoadView ();
...
// initialser code related to the view
...
View.AutoresizingMask = UIViewAutoresizing.None;
ModalPresentationStyle = UIModalPresentationStyle.PageSheet;
ModalTransitionStyle = UIModalTransitionStyle.CrossDissolve;
}
I've overriden the ShouldAutoRotateToInterfaceOrientation
to always return true as well.
Regardless of whether I use Formsheet / Pagesheet, they both appear the correct width when first launched (whether in landscape or portrait - I'm aware PageSheet will fill the portrait view) however on rotation, the modal view will then fill the screen (as if I had presented the ModalView with FullScreen).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如评论中所述,请尝试以下操作:
LoadView() 来不及设置属性。
上一内容:
请发布一些代码。视图肯定是变暗的,在 4.2 中也是如此。
我假设您在错误的控制器上设置了演示样式,因为“PageSheet”在纵向模式下会转换为全屏。
您必须在要在 moda 视图中显示的控制器上设置演示样式,而不是在正在显示的控制器上设置演示样式。因此,如果您要显示的控制器是“oToShow”,而您显示的控制器是“oCurrent”,则必须为“oToShow”设置样式。
尝试将其设置为 FormSheet,它将始终位于顶部并且永远不会全屏显示。
勒内
As stated in the comment, try this:
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é
您可以通过使用不同的样式来解决这个问题,例如
UIModalPresentationFullScreen: 这是默认样式,顾名思义,模式视图会以全屏方式呈现,与 iPhone
UIModalPresentationPageSheet: 完全一样: 模态视图占据全屏高度,但宽度设置为纵向模式下屏幕的宽度。这意味着当设备处于纵向模式时,它仍然占据全屏。然而,在横向模式下,它使一些底层主视图仍然可见,但由于用户无法与未覆盖的主视图控制器交互而变暗。
UIModalPresentationFormSheet:模态视图的宽度和高度都设置为小于屏幕尺寸。模态视图位于屏幕中央,主视图控制器的未覆盖区域变暗以防止用户交互。如果模态视图使用键盘,则模态视图会向上移动以腾出空间。
UIModalPresentationCurrentContext:模式视图使用与父主视图控制器相同的样式显示。
还记得调整大小和位置,否则它将始终以 PageFormSheet 的默认大小显示。
希望这有帮助
亚历克斯
you can work around it by using a different style, like
UIModalPresentationFullScreen: This is the default style and as the name suggests causes the modal view to be presented full screen exactly as with the iPhone
UIModalPresentationPageSheet: The modal view occupies the full screen height but the width is set to the width of the screen in portrait mode. This means that when the device is in portrait mode it still occupies the full screen. However in landscape mode it leaves some of the underlying master view to still be visible, but dimmed as the user cannot interact with the uncovered master view controller.
UIModalPresentationFormSheet: Both the width and height of the modal view are set to be smaller than the screen size. The modal view is centered on the screen and the uncovered areas of the master view controller are dimmed to prevent user interaction. If the modal view makes used of the keyboard the modal view is moved upwards to make room.
UIModalPresentationCurrentContext: The modal view is displayed using the same style as the parent master view controller.
also remember to adjust size and position because it would otherwise always be shown in PageFormSheet's default size.
hope this helps
Alex