新的iPhone 5屏幕有新的纵横比和新的分辨率(640 x 1136像素)。
开发新的应用程序或将现有应用程序转换到新的屏幕尺寸需要什么?
我们应该记住什么,使应用程序“通用”的旧显示器和新的宽屏纵横比?
新的iPhone 5屏幕有新的纵横比和新的分辨率(640 x 1136像素)。
开发新的应用程序或将现有应用程序转换到新的屏幕尺寸需要什么?
我们应该记住什么,使应用程序“通用”的旧显示器和新的宽屏纵横比?
当前回答
首先,创建两个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文件。
其他回答
值得注意的是,在新的Xcode中,你必须将这个图像文件Default-568h@2x.png添加到资产中
你可以使用这个定义来计算你是否使用基于屏幕大小的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
}
Download and install latest version of Xcode. Set a Launch Screen File for your app (in the general tab of your target settings). This is how you get to use the full size of any screen, including iPad split view sizes in iOS 9. Test your app, and hopefully do nothing else, since everything should work magically if you had set auto resizing masks properly, or used Auto Layout. If you didn't, adjust your view layouts, preferably with Auto Layout. If there is something you have to do for the larger screens specifically, then it looks like you have to check height of [[UIScreen mainScreen] bounds] as there seems to be no specific API for that. As of iOS 8 there are also size classes that abstract screen sizes into regular or compact vertically and horizontally and are recommended way to adapt your UI.
这是一个真正的通用代码,你可以创建3个不同的故事板:
设置你的项目通用模式,用iPhone5 storyboard设置你的主故事iPhone,用ipad target storyboard设置ipad main,现在为iPhone添加新的storyboard target,并修改iPhone 4s或更少的分辨率,现在实现你的appdelegate。m
iPhone4/4s (3/ 3g是一样的)一个iPhone5,并使项目通用,与一个新的Storyboard目标为iPad,现在在AppDelegate。在didFinishLaunching下添加以下代码:
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
UIStoryboard *storyBoard;
CGSize result = [[UIScreen mainScreen] bounds].size;
CGFloat scale = [UIScreen mainScreen].scale;
result = CGSizeMake(result.width *scale, result.height *scale);
//----------------HERE WE SETUP FOR IPHONE4/4s/iPod----------------------
if(result.height == 960){
storyBoard = [UIStoryboard storyboardWithName:@"iPhone4_Storyboard" bundle:nil];
UIViewController *initViewController = [storyBoard instantiateInitialViewController];
[self.window setRootViewController:initViewController];
}
//----------------HERE WE SETUP FOR IPHONE3/3s/iPod----------------------
if(result.height == 480){
storyBoard = [UIStoryboard storyboardWithName:@"iPhone4_Storyboard" bundle:nil];
UIViewController *initViewController = [storyBoard instantiateInitialViewController];
[self.window setRootViewController:initViewController];
}
}
return YES;
}
所以你已经为iPhone 3/ 3g /4/4s/5所有一代的iPod和所有类型的iPad创建了一个通用应用程序
记住将所有IMG与myImage.png和myImage@2x.png集成
你可以手动检查屏幕大小来确定你在哪个设备上:
#define DEVICE_IS_IPHONE5 ([[UIScreen mainScreen] bounds].size.height == 568)
float height = DEVICE_IS_IPHONE5?568:480;
if (height == 568) {
// 4"
} else {
// 3"
}