Xamarin.Forms 强迫横竖屏
只要在MainActivity中设置
this.RequestedOrientation = Android.Content.PM.ScreenOrientation.Portrait;//竖屏,禁止横屏
this.RequestedOrientation = Android.Content.PM.ScreenOrientation.Nosensor;//横屏,禁止竖屏
---------------------
Android:
1 public void ForceLandscape() 2 { 3 GetActivity().RequestedOrientation = ScreenOrientation.Landscape; 4 } 5 6 7 public void ForcePortrait() 8 { 9 GetActivity().RequestedOrientation = ScreenOrientation.Portrait; 10 } 11 12 13 14 public Activity GetActivity() 15 { 16 var activity = (Activity)Forms.Context; 17 return activity; 18 }
IOS:
1 public void ForceLandscape() 2 { 3 UIDevice.CurrentDevice.SetValueForKey(new NSNumber((int)UIInterfaceOrientation.LandscapeLeft), new NSString("orientation")); 4 } 5 6 7 public void ForcePortrait() 8 { 9 UIDevice.CurrentDevice.SetValueForKey(new NSNumber((int)UIInterfaceOrientation.Portrait), new NSString("orientation")); 10 }
原文:https://blog.csdn.net/u012069227/article/details/51437345