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

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

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


当前回答

在这里你可以找到一个很好的教程(MonoTouch,但你也可以使用非MonoTouch项目的信息): http://redth.info/get-your-monotouch-apps-ready-for-iphone-5-ios-6-today/

为你的splash/default屏幕创建一个新图像(640 x 1136像素),名称为Default-568h@2x.png 在iOS模拟器中,转到硬件->设备菜单,并选择“iPhone(视网膜4英寸)” 创建其他图像,例如背景图像 检测iPhone 5加载你的新图像:


public static bool IsTall
{
    get {
        return UIDevice.currentDevice.userInterfaceIdiom
                    == UIUserInterfaceIdiomPhone
                && UIScreen.mainScreen.bounds.size.height
                    * UIScreen.mainScreen.scale >= 1136;
    }
}

private static string tallMagic = "-568h@2x";
public static UIImage FromBundle16x9(string path)
{
    //adopt the -568h@2x naming convention
    if(IsTall())
    {
        var imagePath = Path.GetDirectoryName(path.ToString());
        var imageFile = Path.GetFileNameWithoutExtension(path.ToString());
        var imageExt = Path.GetExtension(path.ToString());
        imageFile = imageFile + tallMagic + imageExt;
        return UIImage.FromFile(Path.Combine(imagePath,imageFile));
    }
    else
    {
        return UIImage.FromBundle(path.ToString());
    }
}

其他回答

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

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

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

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

According to me the best way of dealing with such problems and avoiding couple of condition required for checking the the height of device, is using the relative frame for views or any UI element which you are adding to you view for example: if you are adding some UI element which you want should at the bottom of view or just above tab bar then you should take the y origin with respect to your view's height or with respect to tab bar (if present) and we have auto resizing property as well. I hope this will work for you

如果你需要将一个已经存在的应用程序转换为通用,你需要选择相应的xib文件->show Utilities-> show Size inspector。

在大小检查器中,你可以看到自动调整大小,通过使用这个工具你可以转换到现有的iOS应用程序。

如果你的应用是为iPhone 4S或更早版本开发的,那么它将在iPhone 5上运行letterbox。

为了使你的应用程序适应新的更高的屏幕,你要做的第一件事是将启动图像更改为:Default-568h@2x.png。其大小应为1136x640 (HxW)。是的,在新的屏幕大小中设置默认图像是让你的应用占据整个新iPhone 5屏幕的关键。

(注意,命名约定只适用于默认映像。将另一个图像命名为“Image-568h@2x.png”不会导致它取代“Image@2x.png”被加载。如果你需要为不同的屏幕大小加载不同的图像,你必须通过编程来实现。)

如果你非常非常幸运,可能就是这样……但十有八九,你还得多走几步。

确保你的xib / view使用自动布局来调整自己的大小。 使用spring和struts来调整视图的大小。 如果这对你的应用不够好,设计你的xib/storyboard 的特定屏幕尺寸和以编程方式重新定位 其他。

在极端情况下(当以上都不满足时),设计两个xib并在视图控制器中加载适当的一个。

检测屏幕大小:

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
    CGSize result = [[UIScreen mainScreen] bounds].size;
    if(result.height == 480)
    {
        // iPhone Classic
    }
    if(result.height == 568)
    {
        // iPhone 5
    }
}

在constants.h文件中,你可以添加以下定义语句:

 #define IS_IPAD UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad 
 #define IS_IPHONE UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone
 #define IS_WIDESCREEN (fabs((double)[[UIScreen mainScreen] bounds].size.height - (double)568) < DBL_EPSILON) 
 #define IS_IPHONE_5 (!IS_IPAD && IS_WIDESCREEN)