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

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

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


当前回答

I never faced such an issue with any device as I've had one codebase for all, without any hardcoded values. What I do is to have the maximum sized image as resource instead of one for each device. For example, I would have one for retina display and show it as aspect fit so it will be views as is on every device. Coming to deciding the frame of button, for instance, at run time. For this I use the % value of the patent view, example , if I want the width to be half of parent view take 50 % of parent and same applies for height and center.

有了这个,我甚至不需要xib。

其他回答

首先,创建两个xib并将所有委托,main类附加到xib,然后你可以在你的appdelegate中放入下面提到的条件。M文件在

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 

    if ([[UIScreen mainScreen] bounds].size.height == 568)
        {

        self.ViewController = [[ViewController alloc] initWithNibName:@"ViewControlleriphone5" bundle:nil];
        }

        else
        {
             self.ViewController = [[ViewController alloc] initWithNibName:@"ViewControlleriphone4" bundle:nil];

        }

你可以在程序的任何地方使用它,这取决于你的需求,甚至在你的ViewController类中。最重要的是,您已经为iphone 4(320*480)和iphone 5(320*568)分别创建了两个xib文件。

I never faced such an issue with any device as I've had one codebase for all, without any hardcoded values. What I do is to have the maximum sized image as resource instead of one for each device. For example, I would have one for retina display and show it as aspect fit so it will be views as is on every device. Coming to deciding the frame of button, for instance, at run time. For this I use the % value of the patent view, example , if I want the width to be half of parent view take 50 % of parent and same applies for height and center.

有了这个,我甚至不需要xib。

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

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

使用视图的自动布局功能。它将自动调整到所有分辨率。

为控制器名称后缀为~iphone或~ipad的控制器创建两个xib。在编译时,Xcode将根据设备取正确的xib。

使用大小类,如果你想为iPhone和iPad创建一个单独的xib,如果视图足够简单,可以移植到iPhone和iPad。

你可以使用这个定义来计算你是否使用基于屏幕大小的iPhone 5:

#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )

然后使用简单的if语句:

    if (IS_IPHONE_5) {

    // What ever changes
    }