【问题标题】:Monotouch UIScreen.MainScreen.Bounds not updating properlyMonotouch UIScreen.MainScreen.Bounds 未正确更新
【发布时间】:2011-11-26 11:17:27
【问题描述】:

在mViewController.xib.cs 类中,我需要及时确定任何实例的屏幕高度/宽度。所以我覆盖了以下内容。我让调试器进入这些方法,奇怪的是,无论 iPad 在哪个旋转,它都显示我的高度是 1024,宽度是 768,而实际上它应该交换取决于 iPad 的方向(纵向或风景)。有人可以告诉我我做错了什么吗?

    public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
    {

        RectangleF screeninfo = UIScreen.MainScreen.Bounds;

        float height = screeninfo.Height;
        float width = screeninfo.Width;

        return true;
    }

    public override void DidRotate( UIInterfaceOrientation fromInterfaceOrientation)
    {

        RectangleF screeninfo = UIScreen.MainScreen.Bounds;

        float height = screeninfo.Height;
        float width = screeninfo.Width;
    }       

【问题讨论】:

  • iPad 使用objective-c buddy,而不是c#
  • 伙计,有时候你没有一个奇怪的选择。你认为如果我有一个选择,我会使用objective-c。你认为我喜欢在没有文档、没有帮助、只有你一个人的环境中工作。但是看,我需要这份工作,它可以支付账单。
  • Monotouch 在 c# Haoest 中。

标签: c# ipad


【解决方案1】:

这不是 Monotouch 故障,也不是您的错误;这对所有 iOS 设备都是如此。甚至在 Xcode 中这样做:

NSLog(@"%@",NSStringFromCGRect([[UIScreen mainScreen] bounds]));

产量:

{{0, 0}, {768, 1024}}

无论设备方向如何。只需检查当前设备方向,如果是横向切换大小。我不熟悉 Monotouch 或 C#,但在 Obj-C 中我们有 [[UIDevice currentDevice] orientation] 我假设关键字是相似的。

请注意:iPhone screens. 也是如此

【讨论】:

    猜你喜欢
    • 2021-10-26
    • 2021-11-03
    • 2018-01-20
    • 2020-04-09
    • 2013-04-02
    • 2017-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多