I have a Xamarin.Forms ContentPage that I want to only show in portrait mode. If the user rotates the device I don't want the view to rotate.
This page is navigated to by calling Navigation.PushModalAsync
I have found that the modal-ness of this page basically means I am screwed (hoping that isn't the case).
If I change the page to PushAsync (removing the modal-ness) I can get "close" to making this work. But I think this is a giant hack.
So far I have only attempted to make this work in iOS (haven't tried in Android yet but need to support there too)
In iOS the best I have done is
- Creating a Custom UINavigationController
overriding ShouldAutorotate, PreferredInterfaceOrientationForPresentation, and GetSupportedInterfaceOrientations - Creating a Custom PageRenderer
overriding ShouldAutorotate, PreferredInterfaceOrientationForPresentation, and GetSupportedInterfaceOrientations - Passing a message from inside Xamarin Forms when i want to show this view. (I am using my custom Messaging framework Courier to send the message https://www.nuget.org/packages/Courier/)
- Subscribing for the message in AppDelegate
- When I get the message in AppDelegate calling window.RootViewController.PresentViewController passing in my custom NavigationController. Something like this:
var customRenderer = new PortraitRenderer();
var navigationController = new PortraitNavigationController(customRenderer);
window.RootViewController.PresentViewController(navigationController,true,null);
This "almost" works. It does lock the page to Portrait and I see the title of my page correctly. But the actual content on the page doesn't render so I just get a white page....
Please tell me there is a simpler way to make this work (and a cross platform way)?