Je souhaite détecter l'orientation actuelle de l'appareil.Enregistrement pour UIDeviceOrientation
Alors, je la ligne de code
Note: Il me donne l'orientation même si je l'enregistre pas
-(IBAction) deviceOrientationChanged:(id) sender{
NSLog(@"Device Orientation= %d",[[UIDevice currentDevice] orientation]);
}
Quand je change l'orientation, sur un bouton événement click je reçois l'orientation de l'appareil.
Mais, le document dit que vous devez d'abord l'enregistrer, puis utilisez le code ci-dessus.
Remarque: Dans le code ci-dessous j'ai appareil enregistré pour recevoir une notification d'orientation de l'appareil
-(IBAction) deviceOrientationChanged:(id) sender{
if(![[UIDevice currentDevice] isGeneratingDeviceOrientationNotifications]){
//This statement is called very time when I click on the button. I expected to execute only once.
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
}
NSLog(@"Device Orientation= %d",[[UIDevice currentDevice] orientation]);
}
Donc, je ne suis pas en mesure passer à travers le moyen idéal pour obtenir l'orientation de l'appareil.
Il est écrit "La valeur de cette propriété renvoie toujours 0, sauf si les notifications d'orientation ont été activées en appelant beginGeneratingDeviceOrientationNotifications." où property fait référence à la propriété "orientation" de UIDevice – andyPaul