编码为iphone 5屏幕
问题描述:
我采取了一个普遍的项目。我已经为iPhone 5屏幕编码,但它没有检测到它。编码为iphone 5屏幕
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
//ui for ipad
}
else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568) {
tableView.frame = CGRectMake(0, 40, 320 ,508);
}
else {
tableView.frame = CGRectMake(0, 40, 320 ,420);
}
}
虽然不起作用。当我在iPhone 5上调试代码时screenBounds = 320 * 480。
我哪里错了?
答
尝试使用这种检测iPhone 5,而不是:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
CGSize theHeight = [[UIScreen mainScreen] bounds].size;
if(theHeight.height == 568) {
// iPhone 5
tableView.frame = CGRectMake(0, 40, 320 ,508);
}
else {
// iPhone 4
tableView.frame = CGRectMake(0, 40, 320 ,420);
}
}
另外,您可以定义此:
#define IS_IPHONE5 (([[UIScreen mainScreen] bounds].size.height-568)?NO:YES)
每当你需要找出如果它是你可以重新使用iPhone 5或没有。
答
从IB选择您的UITableView
,并为所有屏幕选择尺寸为Retina 4
,即使是主窗口xib文件。这工作得很好,甚至在iPhone 4
答
试试这个代码::
if ([[UIScreen mainScreen] bounds].size.height == 568)
{
[tableView setFrame:CGRectMake(0, 40, 320 ,508)];
}
else if ([[UIScreen mainScreen] bounds].size.height == 480)
{
[tableView setFrame:CGRectMake(0, 40, 320 ,420)];
}
希望,它会帮助你。
谢谢。
答
它是如此简单的检测iPhone5的屏幕, 只要写
#define IS_IPHONE5 (([[UIScreen mainScreen] bounds].size.height-568)?NO:YES)
....你可以进一步检查iPhone5的屏幕像if(IS_IPHONE5)
。
答
此代码工作正常,我
#define IS_IPHONE_5 (fabs((double)[ [ UIScreen mainScreen ] bounds ].size.height - (double)568) < DBL_EPSILON)
if (IS_IPHONE_5)
{
//iphone 5
}
NNO需要的帧.....只是设置Autoresizing .... :) – 2013-03-20 09:37:22
您不需要为tableview设置框架。它会自动自动调整 – 2013-03-20 09:37:32
您的代码应该按原样工作。你是否在你的info.plist中设置了4“显示器的Default.png? – Till 2013-03-20 09:38:45