Search code examples
c#iosxamarinxamarin.iosmvvmcross

Controlling all presented modals iOS


I have a Xamarin iOS app where I am presenting several modals one after the other.

Modal1 -> Modal2 -> Modal3 -> etc.

I would like to control and move all of their Frames. Is there any way that I can access all the modals that I have presented?

I tried something like:

var rootView = UIApplication.SharedApplication.KeyWindow.RootViewController.PresentedViewController;
        foreach (UIView v in rootView)
        {
            //some code
        }

Any tips would be very much appreciated. Thanks!


Solution

  • Try to use the following code :

    public void GetAllMoadlViewController ()
        {
    
            UIViewController presentViewController = this.PresentingViewController;
            UIViewController lastVC = this;
    
            while(presentViewController!=null)
            {
                // One by one to get all ModalViewController that you present 
                var temp = presentViewController;
    
                presentViewController = presentViewController.PresentingViewController;
    
                lastVC = temp;
    
                //do some thing you want 
    
            }
    
        }