UIScreen.MainScreen.Bounds.Height and UIScreen.MainScreen.Bo

本文关键字:UIScreen MainScreen Bo and Bounds Height | 更新日期: 2023-09-27 18:26:19

我最近完成并更新了我的Xamarin iOS项目,我过去可以调用以下代码来检索屏幕宽度和高度:

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。我试着创建一个新项目,尝试同样的事情,但我遇到了同样的问题。现在如何检索主屏幕的宽度和高度?

UIScreen.MainScreen.Bounds.Height and UIScreen.MainScreen.Bo

这看起来像是Visual Studio插件中的一个错误,以前已经报告过:http://forums.xamarin.com/discussion/comment/80994/#Comment_80994

解决方法是同时使用Xamarin Studio(在Mac上)。

如果您能在http://bugzilla.xamarin.com与您的项目,以便我们可以修复它。