新的iPhone 5屏幕有新的纵横比和新的分辨率(640 x 1136像素)。
开发新的应用程序或将现有应用程序转换到新的屏幕尺寸需要什么?
我们应该记住什么,使应用程序“通用”的旧显示器和新的宽屏纵横比?
新的iPhone 5屏幕有新的纵横比和新的分辨率(640 x 1136像素)。
开发新的应用程序或将现有应用程序转换到新的屏幕尺寸需要什么?
我们应该记住什么,使应用程序“通用”的旧显示器和新的宽屏纵横比?
当前回答
这是一个真正的通用代码,你可以创建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集成
其他回答
而不是使用一组条件,您可以自动调整您的视图使用屏幕大小。
int h = [[UIScreen mainScreen] bounds].size.height;
int w = [[UIScreen mainScreen] bounds].size.width;
self.imageView.frame = CGRectMake(20, 80, (h-200), (w-100));
在我的情况下,我想要一个视图,填补在顶部的一些输入字段和底部的一些按钮之间的空间,所以固定的左上角和变量右下角基于屏幕大小。我的应用程序用相机拍摄的照片填充图像视图,所以我想要尽可能多的空间。
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。
我解决了这个问题。只需要在图像中添加~568h@2x后缀,在xib的图像中添加~568h。不需要更多的运行时检查或代码更改。
在iOS设备和iOS模拟器上测试时,有一个小问题。看起来模拟器(XCode 6.0.1)在[[UIScreen mainScreen] bounds]中给出了宽度和高度的切换值。大小,取决于设备方向。
因此,在确定正确的物理屏幕尺寸时,这可能是一个问题。此代码还有助于区分所有2014年。iPhone型号:
iPhone4s iPhone5(和iPhone5s) iPhone6(及iPhone6+)
它也可以很容易地改变,使区别,如iPhone6从iPhone6+。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)
{
if (iOSDeviceScreenSize.width > 568 || // for iOS devices
iOSDeviceScreenSize.height > 568) // for iOS simulator
{ // iPhone 6 and iPhone 6+
// Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone6
storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone6" bundle:nil];
NSLog(@"loaded iPhone6 Storyboard");
}
else if (iOSDeviceScreenSize.width == 568 || // for iOS devices
iOSDeviceScreenSize.height == 568) // for iOS simulator
{ // iPhone 5 and iPod Touch 5th generation: 4 inch screen (diagonally measured)
// Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone5
storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone5" bundle:nil];
NSLog(@"loaded iPhone5 Storyboard");
}
else
{ // iPhone 3GS, 4, and 4S and iPod Touch 3rd and 4th generation: 3.5 inch screen (diagonally measured)
// Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone4
storyboard = [UIStoryboard story boardWithName:@"MainStoryboard_iPhone" bundle:nil];
NSLog(@"loaded iPhone4 Storyboard");
}
}
else if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
{ // The iOS device = iPad
storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPadnew" bundle:nil];
NSLog(@"loaded iPad Storyboard");
}
// rest my code
}
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