2014-09-20 20 views

risposta

7

[UIScreen mainScreen].currentMode rapporti:

<UIScreenMode: 0x17802f240; size = 1242.000000 x 2208.000000> // STANDARD 
<UIScreenMode: 0x178226be0; size = 1125.000000 x 2001.000000> // ZOOMED 
7

C'è un nuovo membro

[[UIScreen mainScreen] nativeScale] 

che dovrebbe fare quello che vuoi. E 'disponibile solo su iOS 8, quindi avrai bisogno di custodirlo

+1

Questo ha funzionato per me! Dovevo semplicemente aggiungere mainScreen(). "UIScreen.mainScreen(). NativeScale". Molto utile per ottenere immagini da un servizio Web in base alla loro larghezza e altezza e in una vista immagine: D – nmdias

11

Il seguente codice può essere utilizzato per ottenere bounds, coordinateSpace, nativeScale e scale, vale a dire su un iPhone 6 Plus il nativeScale è 2.608 e quando il dispositivo in l'esecuzione in modalità ingrandita è 2.88 (nota che è diverso nel simulatore):

UIScreen *mainScreen = [UIScreen mainScreen]; 
NSLog(@"Screen bounds: %@, Screen resolution: %@, scale: %f, nativeScale: %f", 
      NSStringFromCGRect(mainScreen.bounds), mainScreen.coordinateSpace, mainScreen.scale, mainScreen.nativeScale); 

codice per rilevare iPhone 6 Plus:

-(BOOL)iPhone6PlusDevice{ 
    // Scale is 3 currently only for iPhone 6 Plus 
    if ([UIScreen mainScreen].scale > 2.9) return YES; 
    return NO; 
} 

o

-(BOOL)iPhone6PlusUnZoomed{ 
     if ([self iPhone6PlusDevice]){ 
      if ([UIScreen mainScreen].bounds.size.height > 720.0) return YES; // Height is 736, but 667 when zoomed. 
     } 
     return NO; 
    } 

Nota: Se si sta verificando per iPhone 6 Plus, per regolare l'interfaccia utente allora Non tiratevi contare su .nativeScale, perché il simulatore e un dispositivo vero e proprio danno risultati diversi.

+2

Sto eseguendo la mia estensione nella nuova app Messaggi che è stata correttamente aggiornata per le nuove dimensioni dello schermo in iOS8 (ad esempio una che è non 'ingrandito'), e 'screenScale: 3.000000', e' nativeScale: 2.608696' – barfoon

+0

@barfoon quali sono state le risoluzioni dello schermo riportate? Dato che vivo in un paese senza negozio Apple, non sono stato in grado di acquistare il nuovo iPhone 6 Plus. –

+0

nativeScale non ha a che fare con l'esecuzione dell'app in modalità ridimensionata o meno: http://stackoverflow.com/questions/25871858/what-is-the-difference-between-nativescale-and-scale-on- uiscreen-in-ios8 – HHHH

5

Queste opzioni sono utilizzate per rilevare dispositivi iPhone.

#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) 
#define IS_IPHONE_5 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 568.0) 
#define IS_IPHONE_6 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 667.0) 
#define IS_IPHONE_6PLUS (IS_IPHONE && [[UIScreen mainScreen] nativeScale] == 3.0f) 
#define IS_IPHONE_6_PLUS (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 736.0) 
#define IS_RETINA ([[UIScreen mainScreen] scale] == 2.0) 
+0

Poiché iOS 8 '[UIScreen mainScreen] .bounds.size' è diventato dipendente dall'orientamento e queste macro sono interrotte in modalità orizzontale. Potrebbe essere risolto utilizzando MAX (larghezza, altezza) per il confronto dei valori. Si prega di vedere la mia risposta qui sotto. – xZenon

5

macro Aggiornato da Paula Chavarría di answer per iOS 8 (dove [UIScreen mainScreen].bounds.size è orientamento dipendente):

#define IS_OS_8_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) 
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) 
#define IS_IPHONE_5 (IS_IPHONE && (MAX([[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width) == 568.0) && ((IS_OS_8_OR_LATER && [UIScreen mainScreen].nativeScale == [UIScreen mainScreen].scale) || !IS_OS_8_OR_LATER)) 
#define IS_STANDARD_IPHONE_6 (IS_IPHONE && MAX([[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width) == 667.0 && IS_OS_8_OR_LATER && [UIScreen mainScreen].nativeScale == [UIScreen mainScreen].scale) 
#define IS_ZOOMED_IPHONE_6 (IS_IPHONE && MAX([[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width) == 568.0 && IS_OS_8_OR_LATER && [UIScreen mainScreen].nativeScale > [UIScreen mainScreen].scale) 
#define IS_STANDARD_IPHONE_6_PLUS (IS_IPHONE && MAX([[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width) == 736.0) 
#define IS_ZOOMED_IPHONE_6_PLUS (IS_IPHONE && MAX([[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width) == 667.0 && IS_OS_8_OR_LATER && [UIScreen mainScreen].nativeScale < [UIScreen mainScreen].scale) 
#define IS_IPHONE_6 (IS_STANDARD_IPHONE_6 || IS_ZOOMED_IPHONE_6) 
#define IS_IPHONE_6_PLUS (IS_STANDARD_IPHONE_6_PLUS || IS_ZOOMED_IPHONE_6_PLUS) 
Problemi correlati