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

iOS 6应用程序-如何处理iPhone 5的屏幕大小?,iphone,ios,iphone-5,Iphone,Ios,Iphone 5,可能重复: 我只是想知道我们应该如何应对iPhone 5更大的屏幕尺寸 由于它有更多的高度像素,像GCRectMake这样使用坐标的东西(由于视网膜/非视网膜问题,像素只增加了一倍)在不同版本之间无法无缝工作,就像我们得到 我们会像iPad一样设计两个故事板吗 我个人认为,苹果不会像许多答案所说的那样,每次你必须画东西时都要求你检查屏幕大小。iPad会发生这种情况吗 我认为您可以使用[UIScreen mainScreen].bounds.size.height并计算对象的步长。计算步长时,可

可能重复:

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


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

我们会像iPad一样设计两个故事板吗


我个人认为,苹果不会像许多答案所说的那样,每次你必须画东西时都要求你检查屏幕大小。iPad会发生这种情况吗

我认为您可以使用
[UIScreen mainScreen].bounds.size.height
并计算对象的步长。计算步长时,可以设置两种分辨率的坐标

或者你可以得到上面的高度和
if(iphone5)然后。。。否则如果(iphone4)那么。。。else if(ipad)
。像这样的

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


由于它有更多的高度像素,像GCRectMake这样使用坐标的东西在不同版本之间无法无缝工作,就像我们得到视网膜时发生的那样

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


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

这样的东西,从我今天的演示中可以看出,所有的应用程序都将继续在垂直拉伸的屏幕上工作。他们将被字母框或基本上额外的88点的高度将是简单的黑色

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

但是,如果您必须支持较旧的iOS,那么这实际上取决于您的应用程序。使用标准导航栏和/或标签栏的大多数应用程序可以简单地在中间扩展内容以使用额外的点。将中心内容的自动调整大小遮罩设置为在两个方向上展开

view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
对于表格视图来说,它的开箱即用效果非常好,但是,如果你的应用程序使用像素完美的布局来显示内容,那么你最好的选择就是重新想象内容,使其能够适应不同的高度

如果不可能,那么剩下的唯一选择就是拥有两个UI(iPhone5之前的版本和iPhone5)

如果这听起来很难看,那么您可以使用默认的字母框模型,其中额外的点/像素只显示为黑色

编辑

要使您的应用程序与iPhone5配合使用,您需要添加launcher图像的视网膜版本。它应该命名为
Default-568h@2x.png
。而且它必须是视网膜质量-这里没有向后兼容性:)

您还可以从Xcode中选择此图像。转到目标,在摘要部分下,查找启动图像。图像的大小必须为640x1136像素。如果有帮助的话,这里有一个在哪里找到它的截图


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

我必须做到以下几点:

iOS 6中的自动旋转正在改变。在iOS 6中,UIViewController的
shouldAutorotateToInterfaceOrientation:
方法不受欢迎。取而代之的是,您应该使用
支持的interfaceorientationsforwindow:
shouldAutorotate
方法。 因此,我添加了这些新方法(并保留旧方法以实现iOS 5兼容性):

  • 使用视图控制器的
    viewWillLayoutSubviews
    方法,并使用视图的边框调整布局
  • 模态视图控制器:将旋转接口方向:持续时间:,
    WillAnimateRotationInterfaceOrientation:持续时间:
    ,和
    didRotateFromInterfaceOrientation:
    不再调用方法 在
    本身-例如,
    presentViewController:animated:completion:
  • 然后我修复了需要自动布局的视图
  • 将启动视图模拟器和iTunes商店视图中的图像复制到PhotoShop中,并将其导出为png文件
  • 默认图像的名称为:
    default-568h@2x.png
    尺寸为640×1136。它还允许为相同的纵向模式提供640×1096(状态栏已移除)。如果您的应用程序在iPhone上只允许横向定位,则在横向模式下也可以提供类似的尺寸
  • 我已经放弃了iOS 4的向后兼容性。这样做的主要原因是对
    armv6
    code的支持已被放弃。因此,我现在能够支持的所有设备(运行
    armv7
    )都可以升级到iOS 5
  • 我也正在生成支持iPhone5的armv7s代码,因此可以 不使用任何第三方框架(如Admob等),除非 更新

因为旋转的变化,所以请记住在iOS 5和iOS 6中测试自动旋转。

您需要添加640x1136像素的图像(
默认值)-568h@2x.png
)作为项目的4英寸默认启动图像,它将使用额外的空间(如果不使用简单的基于表格的应用程序,游戏将需要
- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAllButUpsideDown;    
}
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
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
    }
@interface UIDevice (Screen)
typedef enum
{
    iPhone          = 1 << 1,
    iPhoneRetina    = 1 << 2,
    iPhone5         = 1 << 3,
    iPad            = 1 << 4,
    iPadRetina      = 1 << 5

} DeviceType;

+ (DeviceType)deviceType;
@end
#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
if ([UIDevice deviceType] & iPhone) 
if ([UIDevice deviceType] & iPad)
if ([UIDevice deviceType] & iPhone5)
if ([UIDevice currentResolution] == UIDevice_iPhoneHiRes || 
    [UIDevice currentResolution] == UIDevice_iPhoneStandardRes || 
    [UIDevice currentResolution] == UIDevice_iPhoneTallerHiRes)`
if ([[UIScreen mainScreen] bounds].size.height > 960)
if ([[UIScreen mainScreen] bounds].size.height == 568)
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;
}