I was needing an app that is all portrait except certain modal views are landscape, so I did it like this for iOS 10 on MvvmCross 5.0:
Firstly set the orientations your app will need in the Info.plist.
Then you will need to find your [MvxRootPresentation]
, aka your root view.
The root view is the one that will receive the calls from ShouldAutorotate
& GetSupportedInterfaceOrientations
I then pass these down to the visible controllers if they implement the methods both these methods are virtual so if not implemented the default is ShouldRotate = false GetSupportedInterfaceOrientations = AllButUpsideDown
Add ShouldAutorotate
& GetSupportedInterfaceOrientations
methods in the root view like this:
public override bool ShouldAutorotate()
{
return true; // Allows all view to auto rotate if they are wrong orientation
}
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations()
{
var orientation = UIInterfaceOrientationMask.Portrait;
if (VisibleUIViewController != null)
{
var VisibleMvxViewController = VisibleUIViewController as MvxViewController;
if (VisibleMvxViewController != null)
{
// Check if the view is a Modal View by checking for the MvxModalPresentationAttribute
var attribute = VisibleMvxViewController.GetType().GetCustomAttributes(typeof(MvxModalPresentationAttribute), true).FirstOrDefault() as MvxModalPresentationAttribute;
if (attribute != null)
{
// Visible view is a modal
if (!VisibleUIViewController.IsBeingDismissed)
{
// view is not being dismissed so use the orientation of the modal
orientation = VisibleUIViewController.GetSupportedInterfaceOrientations();
}
}
}
}
return orientation;
}
Then on modal views (that have the MvxModalPresentation attribute in my case) you want to change the orientation override this method:
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations()
{
return UIInterfaceOrientationMask.AllButUpsideDown;
}
This solution means you don't need to add any thing to the AppDelegate