新的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.

其他回答

Peter,你真的应该看看Canappi,它为你做了所有这些,你所要做的就是指定这样的布局:

button mySubmitButton 'Sumbit' (100,100,100,30 + 0,88,0,0) { ... }

从那里Canappi将生成正确的objective-c代码,检测应用程序正在运行的设备,并将使用:

(100,100,100,30) for iPhone4
(100,**188**,100,30) for iPhone 5

Canappi的工作原理类似于界面生成器和故事板的结合,除了它是文本形式。如果已经有XIB文件,可以转换它们,这样就不必从头重新创建整个UI。

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

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

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

我建议在你的应用程序中根据你的UI界面使用自动调整蒙版,这节省了很多麻烦,比为iPhone 4和5屏幕制作不同的UI更好。

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.

有时候(对于预storyboard应用程序),如果布局会有足够的不同,在viewController init中根据设备指定不同的xib是值得的(参见这个问题-你需要修改代码来处理iPhone 5),因为如果你需要不同的图形,再多的自动调整蒙版也不会起作用。

-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

    NSString *myNibName;
    if ([MyDeviceInfoUtility isiPhone5]) myNibName = @"MyNibIP5";
    else myNibName = @"MyNib";

    if ((self = [super initWithNibName:myNibName bundle:nibBundleOrNil])) {


...

这对于针对旧iOS版本的应用程序非常有用。