C# UIScreen.MainScreen.Bounds.Height和UIScreen.MainScreen.Bounds.Width均为0
我最近对我的Xamarin iOS项目进行了更新,并使用以下代码检索屏幕宽度和高度:C# UIScreen.MainScreen.Bounds.Height和UIScreen.MainScreen.Bounds.Width均为0,c#,ios,xamarin.ios,xamarin,C#,Ios,Xamarin.ios,Xamarin,我最近对我的Xamarin iOS项目进行了更新,并使用以下代码检索屏幕宽度和高度: if (orientation == UIInterfaceOrientation.LandscapeLeft || orientation == UIInterfaceOrientation.LandscapeRight) return new RectangleF(UIScreen.MainScreen.Bounds.X, UIScreen.MainScreen.Bounds.Y, UIScreen
if (orientation == UIInterfaceOrientation.LandscapeLeft || orientation == UIInterfaceOrientation.LandscapeRight)
return new RectangleF(UIScreen.MainScreen.Bounds.X, UIScreen.MainScreen.Bounds.Y, UIScreen.MainScreen.Bounds.Height, UIScreen.MainScreen.Bounds.Width);
但是,现在随着更新,边界是使用CGRect设置的,因此我的代码更改为:
if (orientation == UIInterfaceOrientation.LandscapeLeft || orientation == UIInterfaceOrientation.LandscapeRight)
return new CGRect(UIScreen.MainScreen.Bounds.X, UIScreen.MainScreen.Bounds.Y, UIScreen.MainScreen.Bounds.Height, UIScreen.MainScreen.Bounds.Width);
现在,当我尝试这样做时,高度和宽度返回0。我试图创建一个新项目,尝试同样的事情,但我遇到了同样的问题。现在如何检索主屏幕的宽度和高度?这似乎是Visual Studio插件中的一个错误,以前有过报告: 解决方法是同时使用Xamarin Studio(在Mac上)
如果您能在您的项目中提交一个bug,以便我们能够修复它,我们将不胜感激。您使用的是Xamarin Studio还是Visual Studio?我使用的是Visual Studio?您使用的是哪种生命周期方法?