I am presenting a modal view controller while continuing to display the main screen beneath it, using one of the UIModalPresentationStyle
values in the subject. I'm using MVVMCross (not sure if that matters). Code looks something like
var alertView = UIAlertController.Create(
ViewModel.Configuration.Title,
ViewModel.Configuration.Description,
UIAlertControllerStyle.Alert);
UIViewController presentingViewController = new UIViewController();
var window = new UIWindow(UIScreen.MainScreen.Bounds);
presentingViewController.View.BackgroundColor = UIColor.Clear;
window.RootViewController = _presentingViewController;
window.WindowLevel = UIWindowLevel.Alert + 1;
window.MakeKeyAndVisible();
presentingViewController.PresentViewController(alertController, true, null);
When I close the modal window:
alertView?.DismissViewController(true, null);
presentingViewController?.DismissViewController(true, null);
...
await _navigationService.Navigation.Close(this);
After closing, the main screen behind it is frozen and won't respond to any tap events. If I use a different UIModalPresentationStyle
, like FormSheet
or CurrentContext
, I don't have the freezing problem, but the main screen turns black when the modal window appears.
I prefer to display the main screen behind the modal window. Any suggestions are appreciated, thanks.
Answers
I don't see you presenting a modal view controller anywhere in that code. Also not sure why you are creating a new window? Also i seems you initialize the variable
presentingViewController
but then assign the variable_presentingViewController
(note the leading underscore) to the UIWindow's RootViewController. Perhaps just a typo, but typos like these make it hard to know what may be going on. Some more code might be helpful, especially knowing the context that the code is being called from, i.e is all of the above happen on app start in the FinsishedLaunching method of your AppDelegate? Your creating a new UIWindow would leave me to believe such as usually only one UIWindow is created per app.Thanks for the reply, and sorry for the confusing code.
The
MvxViewController
implementation also implementsIMvxOverridePresentationAttribute
. The issue was resolved by getting rid of everything below thealertView
definition, and callingas well as setting
MvxModalPresentationAttribute.WrapInNavigationController = true