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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM