我参加了一个普遍的项目。我为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 。
我哪里错了?
答案 0 :(得分:3)
检测iPhone5屏幕非常简单, 只需写下
#define IS_IPHONE5 (([[UIScreen mainScreen] bounds].size.height-568)?NO:YES)
....你可以进一步检查iPhone {5}的屏幕,如if(IS_IPHONE5)
。
答案 1 :(得分:1)
从IB中选择UITableView
并为所有屏幕选择大小为Retina 4
,甚至是主窗口xib文件。即使在iPhone 4上也能正常工作。
答案 2 :(得分:1)
为iphone 5.Default-568h@2x.png文件添加启动画面,然后工作正常
答案 3 :(得分:1)
此代码适用于我
#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
if (IS_IPHONE_5)
{
//iphone 5
}
答案 4 :(得分:0)
我使用此代码检查iPhone 5设备。
float scrnheight = [[UIScreen mainScreen] bounds].size.height ;
if(scrnheight == 568.0f)
{
self.isIphone5 = true;
}
答案 5 :(得分:0)
尝试使用它来检测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,都可以重复使用。
答案 6 :(得分:0)
试试这段代码::
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)];
}
希望,它会帮助你。
感谢。