【问题标题】:ios 6.0 and Screen resolution for iphone 5 in simulator [closed]ios 6.0和模拟器中iphone 5的屏幕分辨率[关闭]
【发布时间】:2013-01-03 14:55:46
【问题描述】:

我想将已经在应用商店中发布的功能齐全的应用移植到 ios 6.0 和 iPhone 5 上,以避免那些黑沙盒。

我已添加 Default-568h@2x.png 图像以启用 iphone 5 分辨率支持,黑框不再显示在模拟器中。

但是当我检查屏幕的分辨率 ([UIScreen mainScreen]) 以检测 iPhone 5 时,我总是得到 320x568 的分辨率。我做错了什么?

【问题讨论】:

  • 320x568 (Width x Height) 是正确的,注意 Default-568h@2x.png 里面有 568 表示它是 iPhone 5 的高度。 stackoverflow.com/questions/13399075/screen-size-of-iphone-5/…
  • 此外,如果您将应用程序更新到 iOS 6,它们可能无法在低于该版本的任何设备上运行。你应该只更新 iPhone 5 而不是 iOS6。

标签: iphone ios simulator


【解决方案1】:

in iPhone App How to detect the screen resolution of the device

Jman012 对您的问题的回答:

CGRect screenBounds = [[UIScreen mainScreen] bounds];

这将为您提供整个屏幕的分辨率(以点为单位),因此对于 iPhone,它通常为 320x480。即使 iPhone4 的屏幕尺寸更大,iOS 仍然返回 320x480 而不是 640x960。这主要是因为旧应用程序中断。

CGFloat screenScale = [[UIScreen mainScreen] scale];

这将为您提供屏幕的比例。对于所有没有 Retina 显示屏的 iPhone 和 iPodTouch,将返回 1.0f,而 Retina Display 设备将返回 2.0f。 现在,如果您想获取 iOS 设备屏幕的像素宽度和高度,您只需要做一件简单的事情。

CGSize screenSize = CGSizeMake(screenBounds.size.width * screenScale, screenBounds.size.height * screenScale);

乘以屏幕的比例可以得到实际的像素分辨率。 这段代码的用处在于它可以在 Apple 的后续产品中使用,例如,如果 iPad 获得了 Retina 显示屏,那么使用比例尺将始终为您提供真正的像素分辨率。

http://developer.apple.com/library/ios/#documentation/2DDrawing/Conceptual/DrawingPrintingiOS/GraphicsDrawingOverview/GraphicsDrawingOverview.html#//apple_ref/doc/uid/TP40010156-CH14-SW7

【讨论】:

    猜你喜欢
    • 2016-06-28
    • 1970-01-01
    • 2011-06-13
    • 2015-12-03
    • 2012-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多