新的iPhone 5屏幕有新的纵横比和新的分辨率(640 x 1136像素)。
开发新的应用程序或将现有应用程序转换到新的屏幕尺寸需要什么?
我们应该记住什么,使应用程序“通用”的旧显示器和新的宽屏纵横比?
新的iPhone 5屏幕有新的纵横比和新的分辨率(640 x 1136像素)。
开发新的应用程序或将现有应用程序转换到新的屏幕尺寸需要什么?
我们应该记住什么,使应用程序“通用”的旧显示器和新的宽屏纵横比?
当前回答
如果你需要将一个已经存在的应用程序转换为通用,你需要选择相应的xib文件->show Utilities-> show Size inspector。
在大小检查器中,你可以看到自动调整大小,通过使用这个工具你可以转换到现有的iOS应用程序。
其他回答
在横屏模式下,使用568检查边界将失败。iPhone 5只在纵向模式下启动,但如果你想支持旋转,那么iPhone 5的“check”也需要处理这种情况。
这是一个宏,它处理方向状态:
#define IS_IPHONE_5 (CGSizeEqualToSize([[UIScreen mainScreen] preferredMode].size, CGSizeMake(640, 1136)))
'preferredMode'调用的使用来自我几个小时前读的另一篇文章,所以我没有想到这个想法。
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。
在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
}
首先显示这张图片。在那个图像中,你显示了视网膜4支持的警告,所以点击这个警告,然后点击添加,这样你的视网膜4启动屏幕自动添加到你的项目中。
在你使用这段代码之后
if([[UIScreen mainScreen] bounds].size.height == 568)
{
// For iphone 5
}
else
{
// For iphone 4 or less
}
你可以使用这个定义来计算你是否使用基于屏幕大小的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
}