Hello,
Maui doesn't provide a cross platform property to change the screen orientation, but Maui gives access to the underlying native API
Please refer to this document about Invoke platform code
Android we can change the Orientation by RequestedOrientation, set the ScreenOrientation directly.
//Set ScreenOrientation to Landscape
MainActivity.Instance.RequestedOrientation = ScreenOrientation.Landscape;
//Set ScreenOrientation to Portrait
MainActivity.Instance.RequestedOrientation = ScreenOrientation.Portrait;
Note: MainActivity.Instance comes from MainActivity.cs
, I define a public static property
iOS: we can use UIDevice.CurrentDevice.SetValueForKey
and set it for different Orientation.
//Set ScreenOrientation to Landscape
UIDevice.CurrentDevice.SetValueForKey(NSNumber.FromNInt((int)(UIInterfaceOrientation.LandscapeLeft)), new NSString("orientation"));
//Set ScreenOrientation to Portrait
UIDevice.CurrentDevice.SetValueForKey(NSNumber.FromNInt((int)(UIInterfaceOrientation.Portrait)), new NSString("orientation"));
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.