可能的重复: 如何为iPhone 5屏幕分辨率开发或迁移应用程序?

我只是想知道我们应该如何应对iPhone 5更大的屏幕。

因为它在高度上有更多的像素,像GCRectMake这样使用坐标的东西(只是由于视网膜/非视网膜问题将像素增加了一倍)在版本之间无法无缝工作,就像我们得到视网膜时发生的那样。

我们是否需要设计两个故事板,就像iPad一样?

我个人不认为苹果会像许多人说的那样,要求你每次画画时都检查屏幕大小。iPad也会这样吗?


当前回答

你需要添加一个640x1136像素的PNG图像(Default-568h@2x.png)作为你的项目的4英寸默认splash图像,它将使用额外的空间(在简单的基于表格的应用程序上没有努力,游戏将需要更多的努力)。

为了处理所有屏幕分辨率,我创建了一个小的UIDevice类别。你可以在这里得到它,但代码如下:

文件UIDevice + Resolutions.h:

enum {
    UIDeviceResolution_Unknown           = 0,
    UIDeviceResolution_iPhoneStandard    = 1,    // iPhone 1,3,3GS Standard Display  (320x480px)
    UIDeviceResolution_iPhoneRetina4    = 2,    // iPhone 4,4S Retina Display 3.5"  (640x960px)
    UIDeviceResolution_iPhoneRetina5     = 3,    // iPhone 5 Retina Display 4"       (640x1136px)
    UIDeviceResolution_iPadStandard      = 4,    // iPad 1,2,mini Standard Display   (1024x768px)
    UIDeviceResolution_iPadRetina        = 5     // iPad 3 Retina Display            (2048x1536px)
}; typedef NSUInteger UIDeviceResolution;

@interface UIDevice (Resolutions)

- (UIDeviceResolution)resolution;

NSString *NSStringFromResolution(UIDeviceResolution resolution);

@end

文件UIDevice + Resolutions.m:

#import "UIDevice+Resolutions.h"

@implementation UIDevice (Resolutions)

- (UIDeviceResolution)resolution
{
    UIDeviceResolution resolution = UIDeviceResolution_Unknown;
    UIScreen *mainScreen = [UIScreen mainScreen];
    CGFloat scale = ([mainScreen respondsToSelector:@selector(scale)] ? mainScreen.scale : 1.0f);
    CGFloat pixelHeight = (CGRectGetHeight(mainScreen.bounds) * scale);

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
        if (scale == 2.0f) {
            if (pixelHeight == 960.0f)
                resolution = UIDeviceResolution_iPhoneRetina4;
            else if (pixelHeight == 1136.0f)
                resolution = UIDeviceResolution_iPhoneRetina5;

        } else if (scale == 1.0f && pixelHeight == 480.0f)
            resolution = UIDeviceResolution_iPhoneStandard;

    } else {
        if (scale == 2.0f && pixelHeight == 2048.0f) {
            resolution = UIDeviceResolution_iPadRetina;

        } else if (scale == 1.0f && pixelHeight == 1024.0f) {
            resolution = UIDeviceResolution_iPadStandard;
        }
    }

    return resolution;
 }

 @end

这就是使用这段代码的方式。

1)添加上述UIDevice+Resolutions.h & UIDevice+Resolutions。M文件到您的项目

2)在ViewController.m中添加一行#import“UIDevice+ resolution .h”

3)添加此代码以检查您正在处理的设备的版本

int valueDevice = [[UIDevice currentDevice] resolution];

    NSLog(@"valueDevice: %d ...", valueDevice);

    if (valueDevice == 0)
    {
        //unknow device - you got me!
    }
    else if (valueDevice == 1)
    {
        //standard iphone 3GS and lower
    }
    else if (valueDevice == 2)
    {
        //iphone 4 & 4S
    }
    else if (valueDevice == 3)
    {
        //iphone 5
    }
    else if (valueDevice == 4)
    {
        //ipad 2
    }
    else if (valueDevice == 5)
    {
        //ipad 3 - retina display
    }

其他回答

我刚刚更新并将我的一个应用程序的iOS 6.0版本发送到商店。这个版本向后兼容iOS 5.0,因此我保留了shouldAutorotateToInterfaceOrientation:方法,并添加了如下所示的新方法。

我必须做到以下几点:

iOS 6中的自动旋转功能正在改变。在ios6中,UIViewController的shouldAutorotateToInterfaceOrientation方法已弃用。在它的地方,你应该使用支持的interfaceorientationsforwindow:和shouldAutorotate方法。 因此,我添加了这些新方法(为了兼容iOS 5,保留了旧方法):

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAllButUpsideDown;    
}

Used the view controller’s viewWillLayoutSubviews method and adjust the layout using the view’s bounds rectangle. Modal view controllers: The willRotateToInterfaceOrientation:duration:, willAnimateRotationToInterfaceOrientation:duration:, and didRotateFromInterfaceOrientation: methods are no longer called on any view controller that makes a full-screen presentation over itself—for example, presentViewController:animated:completion:. Then I fixed the autolayout for views that needed it. Copied images from the simulator for startup view and views for the iTunes store into PhotoShop and exported them as png files. The name of the default image is: Default-568h@2x.png and the size is 640×1136. It´s also allowed to supply 640×1096 for the same portrait mode (Statusbar removed). Similar sizes may also be supplied in landscape mode if your app only allows landscape orientation on the iPhone. I have dropped backward compatibility for iOS 4. The main reason for that is because support for armv6 code has been dropped. Thus, all devices that I am able to support now (running armv7) can be upgraded to iOS 5. I am also generation armv7s code to support the iPhone 5 and thus can not use any third party frameworks (as Admob etc.) until they are updated.

这就是全部,但要记住在iOS 5和iOS 6中测试自动旋转,因为旋转的变化。

No.

if ([[UIScreen mainScreen] bounds].size.height > 960)

iPhone 5是错误的

if ([[UIScreen mainScreen] bounds].size.height == 568)

你需要添加一个640x1136像素的PNG图像(Default-568h@2x.png)作为你的项目的4英寸默认splash图像,它将使用额外的空间(在简单的基于表格的应用程序上没有努力,游戏将需要更多的努力)。

为了处理所有屏幕分辨率,我创建了一个小的UIDevice类别。你可以在这里得到它,但代码如下:

文件UIDevice + Resolutions.h:

enum {
    UIDeviceResolution_Unknown           = 0,
    UIDeviceResolution_iPhoneStandard    = 1,    // iPhone 1,3,3GS Standard Display  (320x480px)
    UIDeviceResolution_iPhoneRetina4    = 2,    // iPhone 4,4S Retina Display 3.5"  (640x960px)
    UIDeviceResolution_iPhoneRetina5     = 3,    // iPhone 5 Retina Display 4"       (640x1136px)
    UIDeviceResolution_iPadStandard      = 4,    // iPad 1,2,mini Standard Display   (1024x768px)
    UIDeviceResolution_iPadRetina        = 5     // iPad 3 Retina Display            (2048x1536px)
}; typedef NSUInteger UIDeviceResolution;

@interface UIDevice (Resolutions)

- (UIDeviceResolution)resolution;

NSString *NSStringFromResolution(UIDeviceResolution resolution);

@end

文件UIDevice + Resolutions.m:

#import "UIDevice+Resolutions.h"

@implementation UIDevice (Resolutions)

- (UIDeviceResolution)resolution
{
    UIDeviceResolution resolution = UIDeviceResolution_Unknown;
    UIScreen *mainScreen = [UIScreen mainScreen];
    CGFloat scale = ([mainScreen respondsToSelector:@selector(scale)] ? mainScreen.scale : 1.0f);
    CGFloat pixelHeight = (CGRectGetHeight(mainScreen.bounds) * scale);

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
        if (scale == 2.0f) {
            if (pixelHeight == 960.0f)
                resolution = UIDeviceResolution_iPhoneRetina4;
            else if (pixelHeight == 1136.0f)
                resolution = UIDeviceResolution_iPhoneRetina5;

        } else if (scale == 1.0f && pixelHeight == 480.0f)
            resolution = UIDeviceResolution_iPhoneStandard;

    } else {
        if (scale == 2.0f && pixelHeight == 2048.0f) {
            resolution = UIDeviceResolution_iPadRetina;

        } else if (scale == 1.0f && pixelHeight == 1024.0f) {
            resolution = UIDeviceResolution_iPadStandard;
        }
    }

    return resolution;
 }

 @end

这就是使用这段代码的方式。

1)添加上述UIDevice+Resolutions.h & UIDevice+Resolutions。M文件到您的项目

2)在ViewController.m中添加一行#import“UIDevice+ resolution .h”

3)添加此代码以检查您正在处理的设备的版本

int valueDevice = [[UIDevice currentDevice] resolution];

    NSLog(@"valueDevice: %d ...", valueDevice);

    if (valueDevice == 0)
    {
        //unknow device - you got me!
    }
    else if (valueDevice == 1)
    {
        //standard iphone 3GS and lower
    }
    else if (valueDevice == 2)
    {
        //iphone 4 & 4S
    }
    else if (valueDevice == 3)
    {
        //iphone 5
    }
    else if (valueDevice == 4)
    {
        //ipad 2
    }
    else if (valueDevice == 5)
    {
        //ipad 3 - retina display
    }

由于它在高度上有更多的像素,像GCRectMake这样使用坐标的东西在版本之间无法无缝工作,就像我们获得Retina时发生的那样。

好吧,它们的工作原理与视网膜显示器相同——只是CoreGraphics坐标系统中的1个单位将对应2个物理像素,但你不需要/不必做任何事情,逻辑保持不变。(你有没有试过在视网膜iPhone上运行你的非视网膜应用程序?)

对于实际的问题:这就是为什么你不应该使用显式的CGRectMakes和co…这就是为什么你有[[UIScreen mainScreen] applicationFrame]这样的东西。

我认为你可以使用[UIScreen mainScreen].bounds.size。高度和计算台阶为您的对象。当你计算步长时,你可以为两个分辨率设置坐标。

或者你可以像上面一样高,如果(iphone5)那么…Else if(iphone4) then…else if (ipad)。就像这样。

如果你使用故事板,那么你必须为新iPhone创建新的。