if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
CGSize result = [[UIScreen mainScreen] bounds].size;
//NSLog(@"phonesize%@",result);
if(result.height > 500){
NSLog(@"iPhone 5");
}
else{
NSLog(@"iPhone 4");
}
}
我的Mac OS是10.7.2和Xcode 4.5.2。我使用上面的代码找到设备是iPhone 4或iPhone 5 当我使用iPhone5时它正在给iPhone4。我确实设置了启动图像和图标图像。还有什么我错过了吗?
答案 0 :(得分:1)
确保项目中有一个名为Default-568h@2x.png
的PNG文件。
答案 1 :(得分:0)
您需要根据屏幕比例result
缩放scale
,然后检查...
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
if ([[UIScreen mainScreen] respondsToSelector: @selector(scale)]) {
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");
}
if(result.height == 1136) {
NSLog(@"iPhone 5");
}
}
else{
NSLog(@"Standard Resolution");
}
}
答案 2 :(得分:0)
尝试使用此代码进行测试。
if ([[UIDevice currentDevice] userInterfaceIdiom] ==UIUserInterfaceIdiomPhone)
{
//device is iPhone
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568) {
//device is iphone 5
//add storyboard/Xib that have large screen (320*568)
} else {
//device is iphone 4
//add story board/Xib that have small screen (320*480)
}
}
else
{
//device is iPad
}
答案 3 :(得分:0)
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568)
{
//iphone 5
else
{
//iphone 4
}
}
else
{
//iPad
}
试试这个可能对你有所帮助......