【问题标题】:How do I find out the screen orientation, in portrait or landscape?如何找出屏幕方向,纵向还是横向?
【发布时间】:2012-07-07 15:24:06
【问题描述】:

我不敢相信这是不可能的。这只是肯定每个人都必须要求的东西之一。

所以,这个:

[UIScreen currentScreen] bounds];

在我的 iPhone 上返回 320 的宽度,无论手机是纵向还是横向。所以我做了这个辅助方法:

+(CGRect)screenFrame {

    CGRect frame = [UIScreen mainScreen].bounds;

    if (UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation])) {
        return frame;
    }
    else {
        CGRect newFrame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.height, frame.size.width);
        return newFrame;
    }

}

这很好用,除非设备平放时,显然这使它认为它处于横向状态,即使屏幕没有变为横向。

如何调整它以使其正常工作?

【问题讨论】:

    标签: iphone objective-c ios frame uiscreen


    【解决方案1】:

    最好的指导(主要是因为“平躺”方向)是使用[[UIApplication sharedApplication] statusBarOrientation]。然后,这将根据应用程序如何调整主窗口的坐标变换矩阵为您提供正确的值。

    【讨论】:

      猜你喜欢
      • 2015-12-30
      • 1970-01-01
      • 2012-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多