可能是重复问题:
如何开发或迁移适用于iPhone 5屏幕分辨率的应用程序?
我想知道我们应该如何处理iPhone 5更大的屏幕尺寸。
由于它的高度有更多像素,使用坐标(并且仅将像素加倍以解决视网膜/非视网膜问题)的GCRectMake之类的东西在版本之间不会无缝工作,就像我们得到Retina时一样。
我们是否需要设计两个故事板,就像iPad一样?
我个人认为,苹果不会要求您每次绘制某些内容时都要检查屏幕大小,就像许多答案所说的那样。这在iPad上发生了吗?
可能是重复问题:
如何开发或迁移适用于iPhone 5屏幕分辨率的应用程序?
我想知道我们应该如何处理iPhone 5更大的屏幕尺寸。
由于它的高度有更多像素,使用坐标(并且仅将像素加倍以解决视网膜/非视网膜问题)的GCRectMake之类的东西在版本之间不会无缝工作,就像我们得到Retina时一样。
我们是否需要设计两个故事板,就像iPad一样?
我个人认为,苹果不会要求您每次绘制某些内容时都要检查屏幕大小,就像许多答案所说的那样。这在iPad上发生了吗?
据我所知,从今天的演示中可以看出,所有应用程序在垂直拉伸屏幕时将继续正常工作。它们将被加上黑边框或者说在高度上的额外的88个点将变成黑色。
如果你只打算支持iOS 6+,那么一定要考虑使用自动布局(Auto Layout)。它可以去除所有固定布局处理,并使用约束来布局。没有任何硬编码,你的生活会变得更简单。
但是,如果你需要支持旧版iOS,则真的取决于你的应用程序。大多数使用标准导航栏和/或选项卡栏的应用程序,可以简单地扩展中间的内容以利用那些额外的点。将中心内容的自动调整蒙版设置为在两个方向上扩展即可。
view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
它对于表视图开箱即用非常出色,但如果您的应用程序使用像素完美布局来显示内容,那么最好的选择是重新设计内容,使其适应不同的高度。
如果这不可行,那么唯一剩下的选项就是拥有两个UI(适用于iPhone 5之前和iPhone 5)。
如果那听起来很丑陋,那么您可以采用默认的letterboxed模型,在其中额外的点/像素只会显示为黑色。
编辑
为了使您的应用程序能够与iPhone 5配合使用,您需要添加一个启动图像的视网膜版本。它应该被命名为Default-568h@2x.png
。它必须是视网膜质量 - 这里没有向后兼容性 :)
您还可以从Xcode中选择此图像。转到目标,在“摘要”部分下找到“启动图像”。该图像的尺寸必须为640x1136像素。如果有帮助,以下是在哪里找到它的截图。
-application:didFinishLaunchingWithOptions:
方法的顶部添加self.window.frame = [UIScreen mainScreen].bounds;
。 - Frank SchmittDefault-568h@2x.png
)添加为项目的4英寸默认启动图像,并且它将使用额外的空间(对于基于简单表格的应用程序而言没有太多的努力,游戏将需要更多的努力)。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
#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 + Resolutions.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
}
UIUserInterfaceIdiomPad
而不是假设 !phone == pad
。 - mvds我刚刚完成了将我的一个应用更新并发送到商店,这个版本向下兼容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:
和didRotateFromInterfaceOrientation:
方法不再在任何全屏显示自己的视图控制器上调用,例如presentViewController:animated:completion:
。Default-568h@2x.png
,大小为640×1136。如果您的应用程序仅允许iPhone处于横向方向,则还可以提供类似大小的横向模式(状态栏已移除)640×1096。如果您的应用程序只允许横向方向,则也可以在纵向模式下提供类似大小。armv6
代码已被删除。因此,现在我能够支持的所有设备(运行armv7
)都可以升级到iOS 5。armv7s
代码,因此无法使用任何第三方框架(如Admob等)直到它们得到更新。这就是全部内容,但请记住要在iOS 5和iOS 6中测试自动旋转,因为旋转方式发生了变化。
不行。
if ([[UIScreen mainScreen] bounds].size.height > 960)
在 iPhone 5 上是错误的。
if ([[UIScreen mainScreen] bounds].size.height == 568)
Default-568h@2x.png
。Apple Docs: App Launch (Default) Images。 - John Erck@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(不考虑屏幕大小),你只需使用:
if ([UIDevice deviceType] & iPhone)
或者if ([UIDevice deviceType] & iPad)
如果你只想检测iPhone 5,可以使用:
if ([UIDevice deviceType] & iPhone5)
与Malcom的答案相反,您需要检查才能确定它是否是iPhone,
if ([UIDevice currentResolution] == UIDevice_iPhoneHiRes ||
[UIDevice currentResolution] == UIDevice_iPhoneStandardRes ||
[UIDevice currentResolution] == UIDevice_iPhoneTallerHiRes)`
两种方法都没有明显的优劣之分,只是个人偏好而已。
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)
。类似这样的东西。
如果您使用storyboards,则需要为新的iPhone创建新的故事板。
CGRectMake(0, 0, 320, 480);
在视网膜屏幕上的效果与非视网膜屏幕上相同。 - user529758