新的iPhone 5屏幕有新的纵横比和新的分辨率(640 x 1136像素)。
开发新的应用程序或将现有应用程序转换到新的屏幕尺寸需要什么?
我们应该记住什么,使应用程序“通用”的旧显示器和新的宽屏纵横比?
新的iPhone 5屏幕有新的纵横比和新的分辨率(640 x 1136像素)。
开发新的应用程序或将现有应用程序转换到新的屏幕尺寸需要什么?
我们应该记住什么,使应用程序“通用”的旧显示器和新的宽屏纵横比?
当前回答
要确定你的应用是否支持iPhone 5 Retina,请使用以下方法: (这可以更健壮地返回显示类型,4S视网膜等,但正如下面所写的,如果iPhone支持iOS5视网膜,它只返回YES或NO)
在一个普通的“。h”文件中添加:
BOOL IS_IPHONE5_RETINA(void);
在一个共同的”。M”文件添加:
BOOL IS_IPHONE5_RETINA(void) {
BOOL isiPhone5Retina = NO;
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
if ([UIScreen mainScreen].scale == 2.0f) {
CGSize result = [[UIScreen mainScreen] bounds].size;
CGFloat scale = [UIScreen mainScreen].scale;
result = CGSizeMake(result.width * scale, result.height * scale);
if(result.height == 960){
//NSLog(@"iPhone 4, 4s Retina Resolution");
}
if(result.height == 1136){
//NSLog(@"iPhone 5 Resolution");
isiPhone5Retina = YES;
}
} else {
//NSLog(@"iPhone Standard Resolution");
}
}
return isiPhone5Retina;
}
其他回答
我想,它不是在所有情况下都能工作,但在我的特定项目中,它避免了我对nib文件的重复:
在common.h中,你可以根据屏幕高度来做这些定义:
#define HEIGHT_IPHONE_5 568
#define IS_IPHONE ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
#define IS_IPHONE_5 ([[UIScreen mainScreen] bounds ].size.height == HEIGHT_IPHONE_5)
在你的基本控制器中:
- (void)viewDidLoad
{
[super viewDidLoad];
if (IS_IPHONE_5) {
CGRect r = self.view.frame;
r.size.height = HEIGHT_IPHONE_5 - 20;
self.view.frame = r;
}
// now the view is stretched properly and not pushed to the bottom
// it is pushed to the top instead...
// other code goes here...
}
通过xib .........很容易迁移iPhone5和iPhone4
UIViewController *viewController3;
if ([[UIScreen mainScreen] bounds].size.height == 568)
{
UIViewController *viewController3 = [[[mainscreenview alloc] initWithNibName:@"iphone5screen" bundle:nil] autorelease];
}
else
{
UIViewController *viewController3 = [[[mainscreenview alloc] initWithNibName:@"iphone4screen" bundle:nil] autorelease];
}
你可以手动检查屏幕大小来确定你在哪个设备上:
#define DEVICE_IS_IPHONE5 ([[UIScreen mainScreen] bounds].size.height == 568)
float height = DEVICE_IS_IPHONE5?568:480;
if (height == 568) {
// 4"
} else {
// 3"
}
在这里你可以找到一个很好的教程(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());
}
}
你可以使用这个定义来计算你是否使用基于屏幕大小的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
}