ios 6.0和iphone 5在模拟器中的屏幕分辨率

时间:2013-01-03 14:55:47

标签: iphone ios simulator

我想将应用程序商店中已发布的功能齐全的应用程序移植到ios 6.0和iPhone 5,以避免使用这些黑色沙箱。

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

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

1 个答案:

答案 0 :(得分:2)

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显示设备将提供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

相关问题