目前我使用这种方法来检测取向和设备:
它适用于iPhone手机,但这些是与iPad的一个问题,那就是无论取向是, [[UIScreen mainScreen] bounds].size.width
总是== 768,和[[UIScreen mainScreen] bounds].size.height
总是== 1024这有什么错我的编码?
+(NSString*)GetOrientation{
if([UIScreen mainScreen].bounds.size.width < [UIScreen mainScreen].bounds.size.height){
NSLog(@"Potrait");
return @"Potrait";
}
else{
NSLog(@"Landscape");
return @"Landscape";
}
}
+(NSString*)GetDeviceAccordingToScreenSize:(UIViewController*)ctrl{
if ([[UIDevice currentDevice].model isEqualToString:@"iPad"]) {
int screenWidth = [[UIScreen mainScreen] bounds].size.width;
if (screenWidth==768) {
return @"P-iPad";
}else if(screenWidth==1024){
return @"L-iPad";
}else{
return @"ERROR";
}
}else{
if ([[self GetOrientation] isEqualToString:@"Potrait"]) {
int screenHeight = [[UIScreen mainScreen] bounds].size.height;
switch (screenHeight) {
case 667:{
return @"P-iPhone6";
break;
}
case 736:{
return @"P-iPhone6Plus";
break;
}
case 568:{
return @"P-iPhone5";
}
default:{
return @"P-iPhone4";
break;
}
}
}else{
int screenWidth = [[UIScreen mainScreen] bounds].size.width;
// float screenHeight = [[UIScreen mainScreen] bounds].size.height;
switch (screenWidth) {
case 667:{
return @"L-iPhone6";
break;
}
case 736:{
return @"L-iPhone6Plus";
break;
}
case 568:{
return @"L-iPhone5";
break;
}
default:{
return @"L-iPhone4";
break;
}
}
}
}
}
顺便说一句,在扩展你没有访问[UIApplication的sharedApplication]