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 m开发者_JS百科uch 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).
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é
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
View.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
精彩评论