iOS 6应用程序 – 如何处理iPhone 5的屏幕大小?

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

我只是想知道如何处理iPhone 5更大的屏幕尺寸。

由于它的像素高度更高,像GCRectMake这样的使用坐标(以及像素与视网膜/非视网膜问题的两倍)在版本之间将无法正常工作,就像我们获得视网膜时发生的那样。

我们将不得不devise两个故事板,就像iPad一样吗?

我个人不认为苹果会要求你每次画画时都要检查一下屏幕大小,就像很多答案所说的那样。 这是否发生在iPad上?

所有的应用程序将继续在今天的演示中我可以告诉的纵向延伸的屏幕上工作。 他们将是信箱或基本上额外的88点高度将只是黑色。

如果您只打算支持iOS 6+,那么一定要考虑使用自动布局。 它删除所有固定的布局处理,而是使用约束来处理事情。 没有什么是硬编码的,你的生活会变得简单得多。

但是,如果您必须支持较老的iOS,那么这取决于您的应用程序。 大多数使用标准导航栏和/或标签栏的应用程序可以简单地扩展中间的内容以使用该额外的点。 将中心内容的自动调整掩码设置为双向展开。

view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 

如果您的应用程序使用了像素完美的布局来显示内容,那么最好的办法就是重新设想内容,以便适应不同的高度。

如果这不可能,那么唯一的select是有两个用户界面(iPhone 5和iPhone 5之前)。

如果这听起来很丑,那么你可以使用默认的信箱模式,其中额外的点/像素显示黑色。

编辑

要使您的应用程序能够与iPhone 5一起使用,您需要添加启动器映像的视网膜版本。 它应该被命名为Default-568h@2x.png 。 它必须是视网膜质量 – 这里没有向后兼容:)

你也可以从Xcode中select这个图像。 转到目标,然后在“摘要”部分中查找“启动映像”。 图像必须是640×1136像素的大小。 这里有一个屏幕截图,如果有帮助的话。

Xcode截图

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

我已经创build了一个小的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)将#import“UIDevice + Resolutions.h”行添加到您的ViewController.m中

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中正在改变。在iOS 6中,不推荐使用UIViewController的shouldAutorotateToInterfaceOrientation:方法。 在它的地方,你应该使用supportedInterfaceOrientationsForWindow:shouldAutorotate方法。 因此,我添加了这些新的方法(并保持与iOS 5兼容的旧版本):

 - (BOOL)shouldAutorotate { return YES; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskAllButUpsideDown; } 
  • 使用视图控制器的viewWillLayoutSubviews方法,并使用视图的边界矩形调整布局。
  • 模态视图控制器: willRotateToInterfaceOrientation:duration:
    willAnimateRotationToInterfaceOrientation:duration: ,and
    didRotateFromInterfaceOrientation:方法不再在任何视图控制器上调用全屏演示
    本身 – 例如presentViewController:animated:completion:
  • 然后我修复了需要它的视图的自动布局。
  • 将模拟器中的图像复制到iTunes Store的启动视图和视图到PhotoShop中,并将它们导出为png文件。
  • 默认图片的名字是: Default-568h@2x.png ,大小是640×1136。 也可以为相同的人像模式提供640×1096(状态栏已移除)。 如果您的应用只允许在iPhone上横向摆放,则也可以在横向模式下提供类似的尺寸。
  • 我已经降低了iOS 4的向后兼容性。主要原因是因为对armv6代码的支持已经被删除了。 因此,现在我能够支持的所有设备(运行armv7 )都可以升级到iOS 5。
  • 我也是一代armv7s代码,以支持iPhone 5,因此不能使用任何第三方框架(如Admob等),直到他们更新。

这一切都只是记得在iOS 5和iOS 6中testing自旋,因为旋转的变化。

没有。

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

在iPhone 5上是错误的

 if ([[UIScreen mainScreen] bounds].size.height == 568) 
 @interface UIDevice (Screen) typedef enum { iPhone = 1 << 1, iPhoneRetina = 1 << 2, iPhone5 = 1 << 3, iPad = 1 << 4, iPadRetina = 1 << 5 } DeviceType; + (DeviceType)deviceType; @end 

.M

 #import "UIDevice+Screen.h" @implementation UIDevice (Screen) + (DeviceType)deviceType { DeviceType thisDevice = 0; if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { thisDevice |= iPhone; if ([[UIScreen mainScreen] respondsToSelector: @selector(scale)]) { thisDevice |= iPhoneRetina; if ([[UIScreen mainScreen] bounds].size.height == 568) thisDevice |= iPhone5; } } else { thisDevice |= iPad; if ([[UIScreen mainScreen] respondsToSelector: @selector(scale)]) thisDevice |= iPadRetina; } return thisDevice; } @end 

这样,如果你想检测它是否只是一个iPhone或iPad(不pipe屏幕大小),你只需使用:

 if ([UIDevice deviceType] & iPhone) 

要么

 if ([UIDevice deviceType] & iPad) 

如果你想检测只是iPhone 5,你可以使用

 if ([UIDevice deviceType] & iPhone5) 

与Malcoms的回答相反,你需要检查是否是iPhone,

 if ([UIDevice currentResolution] == UIDevice_iPhoneHiRes || [UIDevice currentResolution] == UIDevice_iPhoneStandardRes || [UIDevice currentResolution] == UIDevice_iPhoneTallerHiRes)` 

这两种方式都没有什么优势,只是个人喜好。

帕斯卡对OP问题的评论是正确的。 通过简单地添加图像,它将删除黑色边框,应用程序将使用完整的高度。

您将需要通过确定设备正在使用更大的显示器来对任何CGRects进行调整。 也就是说,如果你需要的东西alignment屏幕的底部。

我相信有一个内置的方法,但我没有看到任何东西,很多仍然是NDA,所以我们在应用程序中使用的方法是一个简单的全局函数。 将以下内容添加到您的.pch文件中,然后添加一个简单的if( is4InchRetina() ) { ... }调用来调整您的CGRects等。

 static BOOL is4InchRetina() { if (![UIApplication sharedApplication].statusBarHidden && (int)[[UIScreen mainScreen] applicationFrame].size.height == 548 || [UIApplication sharedApplication].statusBarHidden && (int)[[UIScreen mainScreen] applicationFrame].size.height == 568) return YES; return NO; } 

我认为你可以使用[UIScreen mainScreen].bounds.size.height和计算你的对象的步骤。 当你计算一步你可以设置两个分辨率的坐标。

或者你可以得到像上面那样的高度, if(iphone5) then... else if(iphone4) then... else if(ipad) 。 像这样的东西。

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

由于它具有更多的像素高度,像使用坐标的GCRectMake之类的东西在版本之间将无法正常工作,就像我们获得视网膜时发生的那样。

那么,他们在Retina显示器上的工作方式也是一样 – CoreGraphics坐标系统中的1个单元将对应2个物理像素,但是您没有/不必做任何事情,逻辑保持不变。 (你有没有试过在视网膜iPhone上运行一个非视网膜应用程序

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