Ios iphone5屏幕编码
我参加了一个通用项目。我已经为iPhone5屏幕编写了代码,但它没有检测到Ios iphone5屏幕编码,ios,objective-c,uitableview,iphone-5,Ios,Objective C,Uitableview,Iphone 5,我参加了一个通用项目。我已经为iPhone5屏幕编写了代码,但它没有检测到 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { //ui for ipad } else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { CGRect screenBounds = [[UIScreen mainScreen] bounds]; if
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设备
float scrnheight = [[UIScreen mainScreen] bounds].size.height ;
if(scrnheight == 568.0f)
{
self.isIphone5 = true;
}
尝试使用此选项检测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,并为所有屏幕(甚至主窗口xib文件)选择尺寸为Retina 4。即使在iPhone4上,这也可以正常工作
请尝试以下代码:
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屏幕非常简单, 只要写 定义为iPhone 5[[UIScreen mainScreen]界限].大小。高度-568?否:是
在.pch文件中。。。。您还可以进一步检查iPhone5屏幕,如ifIS_iPhone5。您为iPhone5添加了闪屏。默认设置-568h@2x.png文件,然后它的工作很好这段代码对我来说很好
#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
if (IS_IPHONE_5)
{
//iphone 5
}
不需要框架。。。。。只需设置自动调整大小…:无需为tableview设置框架。。它会自动调整代码的大小。您在info.plist中为4显示设置了Default.png吗?您为iphone 5添加了启动屏幕。默认设置-568h@2x.png文件那么它的工作如何不同于OP的版本?完全忽略了有问题的代码,复制了它,并假设这会有所帮助。。。