2015-02-10 59 views
1

當我在模擬器iPad的迷你(我現在用ipad 2的配置文件)和iPad的空氣運行顯示UI套件相同的分辨率1024×768ipad mini和ipad air的區別?

它可能會自動調整,但我使用cocos2d的

回答

4

蘋果並不真的希望你能夠檢測到這一點,所以他們沒有提供一個簡單的方法來做到這一點。我想你應該真的問自己爲什麼你需要知道。這就是說,我碰巧有一個'標尺應用程序',這可能是爲數不同的幾個正當理由之一。我把這個在一個類別上的UIDevice

接口:

// UIDevice+JEFkit.h 

typedef NS_ENUM (NSUInteger, deviceClass) { 

deviceClass_iPhone = 0,  
deviceClass_iPhoneTall = 1,  
deviceClass_iPhoneSix = 2,  
deviceClass_iPhoneSixPlus= 3, 

deviceClass_iPadMini = 10, 
deviceClass_iPad = 11, 

deviceClass_unknown 

}; 

@interface UIDevice (JEFkit) 

#pragma mark device type.. 

+(deviceClass)deviceClass; 
//some other stuff.. 
@end 

實現:

+(deviceClass)deviceClass{ 

    NSUInteger greater = ((NSUInteger)fmaxf([[UIScreen mainScreen]bounds].size.width, [[UIScreen mainScreen]bounds].size.height)); 

    switch (greater) { 
    case 480: 
     return deviceClass_iPhone; 
     break; 
    case 568: 
     return deviceClass_iPhoneTall; 
     break; 
    case 667: 
     return deviceClass_iPhoneSix; 
     break; 
    case 736: 
     return deviceClass_iPhoneSixPlus; 
     break; 
    case 1024: 
     // its an ipad, what size ? 
    { 

     size_t size1; 
     sysctlbyname("hw.machine", NULL, &size1, NULL, 0); 
     char *machine1 = malloc(size1 + 1); 
     sysctlbyname("hw.machine", machine1, &size1, NULL, 0); 
     machine1[size1] = 0; 

     if (strcmp(machine1, "iPad1,1") == 0 || strcmp(machine1, "iPad2,1") == 0 || strcmp(machine1, "iPad2,2") == 0 || strcmp(machine1, "iPad2,3") == 0 || strcmp(machine1, "iPad2,4") == 0) { 

     /* iPad 1 or 2 */ 
     free(machine1); 
     return deviceClass_iPad; 
     } 

     if ([[UIScreen mainScreen]respondsToSelector:@selector(scale)]) { 
     if ([[UIScreen mainScreen] scale] < 2.0) { 
      free(machine1); 


      return deviceClass_iPadMini; //all other non-retina full sized iPad devices are eliminated, must be first GEN mini 

      /// nb the iPad simulator also in here.. 

     } 
     }else{ 
     ///does not respond to @selector(scale) 
     /// should not ever happen 

     free(machine1); 
     return deviceClass_iPad; 
     } 

     //ok only retina ipads are left... 
     if (strcmp(machine1, "iPad4,4") == 0 || strcmp(machine1, "iPad4,5") == 0 || strcmp(machine1, "iPad4,6") == 0 || strcmp(machine1, "iPad4,7") == 0 || strcmp(machine1, "iPad4,8") == 0 || strcmp(machine1, "iPad4,9") == 0) { 
     /* 2nd/3rd gen minis w retina*/ 


     ////TODO//// 

     /// future retina minis !!! /// 

     free(machine1); 
     return deviceClass_iPadMini; 
     } 

     //known retina minis are eliminated.. 

     free(machine1); 
     return deviceClass_iPad; 
    } 
     break; 
    default: 
     break; 
    } 

    return deviceClass_unknown; 
} 
+0

告訴你什麼是令人印象深刻的+1 – Popeye 2015-02-12 08:37:42

0

您可以使用model方法在類中區分不同的設備。更重要的是,你可以使用這個開源框架https://github.com/erichoracek/UIDevice-Hardware。使用它可能更方便。

+2

如果您確實擁有iPad mini並嘗試此操作,您會發現它會返回與iPad相同的結果!對不起,不好回答:( – Jef 2015-02-10 05:46:14

-1

如果你的問題是關於視網膜與非視網膜然後UIScreen有一堆的查詢方法屏幕參數(例如[UIScreen scale])。

但是,如果你想處理dpi的差異(和相關的按鈕最小尺寸),那麼請看看Determine device (iPhone, iPod Touch) with iPhone SDK。但是警告:設備列表已打開,因此無論何時出現新設備,您都必須更新您的應用。

相關問題