iPhoneSoft : forum iPhone, iPad, Apple Watch, Apple TV et Mac

application iSoft pour le forum iPhoneSoft (iPhone, iPod, iPad, Apple Watch, Apple TV, Mac et services Apple

Forum iPhone, iPod et iPad, Apple TV, Apple Watch et Mac en français par iPhoneSoft pour les systèmes iOS, macOS, tvOS et watchOS

Vous n'êtes pas identifié(e).



#1 11-10-2010 11:55:42

Medhi
Admin

Déterminer si le device est un iPhone ou un iPad et quelle orientation

Comment faire une application universelle sans savoir quel est le device qui fait tourner l'application ?
Alors voici une petite astuce pour faire des constantes utilisables à tous moment

//Ajoutez ses constantes dans le .h de votre AppDelegate
#define DEVICE_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)     // iPad
#define DEVICE_IPHONE_IPOD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) // iPhone ou iPod touch.

#define ORIENTATION_INTERFACE_PORTRAIT (UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation])) // Portrait
#define ORIENTATION_INTERFACE_LANDSCAPE (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) // Paysage
#define ORIENTATION_DEVICE_PORTRAIT (UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation])) // Portrait
#define ORIENTATION_DEVICE_LANDSCAPE (UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation])) // Paysage
#define ORIENTATION_DEVICE_VALID (UIDeviceOrientationIsValidInterfaceOrientation([[UIDevice currentDevice] orientation])) // A plat (marche pour l'iPad seulement)

//Ensuite vous pourrez tester facilement le device dans votre code
if(DEVICE_IPAD) NSLog(@"Je suis un iPad");
if(DEVICE_IPHONE_IPOD) NSLog(@"Je suis un iPhone");


Hors ligne

Pied de page des forums