新的iPhone 5屏幕有新的纵横比和新的分辨率(640 x 1136像素)。

开发新的应用程序或将现有应用程序转换到新的屏幕尺寸需要什么?

我们应该记住什么,使应用程序“通用”的旧显示器和新的宽屏纵横比?


当前回答

Download and install latest version of Xcode. Set a Launch Screen File for your app (in the general tab of your target settings). This is how you get to use the full size of any screen, including iPad split view sizes in iOS 9. Test your app, and hopefully do nothing else, since everything should work magically if you had set auto resizing masks properly, or used Auto Layout. If you didn't, adjust your view layouts, preferably with Auto Layout. If there is something you have to do for the larger screens specifically, then it looks like you have to check height of [[UIScreen mainScreen] bounds] as there seems to be no specific API for that. As of iOS 8 there are also size classes that abstract screen sizes into regular or compact vertically and horizontally and are recommended way to adapt your UI.

其他回答

要确定你的应用是否支持iPhone 5 Retina,请使用以下方法: (这可以更健壮地返回显示类型,4S视网膜等,但正如下面所写的,如果iPhone支持iOS5视网膜,它只返回YES或NO)

在一个普通的“。h”文件中添加:

BOOL IS_IPHONE5_RETINA(void);

在一个共同的”。M”文件添加:

BOOL IS_IPHONE5_RETINA(void) {
    BOOL isiPhone5Retina = NO;
    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
        if ([UIScreen mainScreen].scale == 2.0f) {
            CGSize result = [[UIScreen mainScreen] bounds].size;
            CGFloat scale = [UIScreen mainScreen].scale;
            result = CGSizeMake(result.width * scale, result.height * scale);

            if(result.height == 960){
                //NSLog(@"iPhone 4, 4s Retina Resolution");
            }
            if(result.height == 1136){
                //NSLog(@"iPhone 5 Resolution");
                isiPhone5Retina = YES;
            }
        } else {
            //NSLog(@"iPhone Standard Resolution");
        }
    }
    return isiPhone5Retina;
}

这是一个真正的通用代码,你可以创建3个不同的故事板:

设置你的项目通用模式,用iPhone5 storyboard设置你的主故事iPhone,用ipad target storyboard设置ipad main,现在为iPhone添加新的storyboard target,并修改iPhone 4s或更少的分辨率,现在实现你的appdelegate。m

iPhone4/4s (3/ 3g是一样的)一个iPhone5,并使项目通用,与一个新的Storyboard目标为iPad,现在在AppDelegate。在didFinishLaunching下添加以下代码:

    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
        UIStoryboard *storyBoard;

        CGSize result = [[UIScreen mainScreen] bounds].size;
        CGFloat scale = [UIScreen mainScreen].scale;
        result = CGSizeMake(result.width *scale, result.height *scale);

//----------------HERE WE SETUP FOR IPHONE4/4s/iPod----------------------

        if(result.height == 960){
            storyBoard = [UIStoryboard storyboardWithName:@"iPhone4_Storyboard" bundle:nil];
            UIViewController *initViewController = [storyBoard instantiateInitialViewController];
            [self.window setRootViewController:initViewController];
        }

//----------------HERE WE SETUP FOR IPHONE3/3s/iPod----------------------

        if(result.height == 480){
            storyBoard = [UIStoryboard storyboardWithName:@"iPhone4_Storyboard" bundle:nil];
            UIViewController *initViewController = [storyBoard instantiateInitialViewController];
            [self.window setRootViewController:initViewController];
        }
    }

        return YES;
 }

所以你已经为iPhone 3/ 3g /4/4s/5所有一代的iPod和所有类型的iPad创建了一个通用应用程序

记住将所有IMG与myImage.png和myImage@2x.png集成

而不是使用一组条件,您可以自动调整您的视图使用屏幕大小。

int h = [[UIScreen mainScreen] bounds].size.height;
int w = [[UIScreen mainScreen] bounds].size.width;
self.imageView.frame = CGRectMake(20, 80, (h-200), (w-100));

在我的情况下,我想要一个视图,填补在顶部的一些输入字段和底部的一些按钮之间的空间,所以固定的左上角和变量右下角基于屏幕大小。我的应用程序用相机拍摄的照片填充图像视图,所以我想要尽可能多的空间。

使用xCode 5,在项目>General上选择“迁移到资产目录”。

然后使用“Show in finder”找到你的启动图像,你可以模拟编辑它为640x1136,然后拖到资产目录,如下图所示。

确保iOS7和iOS6 R4部分都有一个640x1136的图像。下次你启动应用程序时,黑条将消失,你的应用程序将使用4英寸的屏幕

在横屏模式下,使用568检查边界将失败。iPhone 5只在纵向模式下启动,但如果你想支持旋转,那么iPhone 5的“check”也需要处理这种情况。

这是一个宏,它处理方向状态:

#define IS_IPHONE_5 (CGSizeEqualToSize([[UIScreen mainScreen] preferredMode].size, CGSizeMake(640, 1136)))

'preferredMode'调用的使用来自我几个小时前读的另一篇文章,所以我没有想到这个想法。