2017-05-10 4 views
0

je suis en utilisant le code suivant, mais continue à me donner 0 valeurs s'il vous plaît vérifier ce que je fais malObjectif c - l'attitude de mouvement de l'appareil valeurs

UILabel *rollLabel = [[UILabel alloc] init]; 
CMQuaternion quat = self.motionManager.deviceMotion.attitude.quaternion; 
float myRoll = radiansToDegrees(atan2(2*(quat.y*quat.w - quat.x*quat.z), 1 - 2*quat.y*quat.y - 2*quat.z*quat.z)) ; 
float myPitch = radiansToDegrees(atan2(2*(quat.x*quat.w + quat.y*quat.z), 1 - 2*quat.x*quat.x - 2*quat.z*quat.z)); 
float myYaw = radiansToDegrees(asin(2*quat.x*quat.y + 2*quat.w*quat.z)); 
[rollLabel setText:[NSString stringWithFormat:@"ROLL = %f , - Pitch = %f, , - Yaw = %f", myRoll, myPitch, myYaw]]; 
rollLabel.frame = CGRectMake(0, 0, 400, 150); 
rollLabel.backgroundColor=[UIColor greenColor]; 
rollLabel.textColor=[UIColor blackColor]; 
[self.view addSubview:rollLabel]; 

merci pour votre aide

+0

toute aide sera reconnaissant – user460024

+0

Comment vous 'self.motionManager' initialiser? – Losiowaty

+0

@property (non atomique, fort) CMMotionManager * motionManager; – user460024

Répondre

1

d'abord je voudrais essayer si tous les objets ne sont pas nuls, vérifiez si vous avez fait le MotionManager lui-même, quelque chose comme:

_motionManager = [[CMMotionManager alloc] init]; 
_motionManager.deviceMotionUpdateInterval = 1.0/60; 
[_motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXArbitraryZVertical]; 

question suivante peut être si votre code est en cours d'exécution sur le thread principal

il y a beaucoup d'options qui peuvent faire en sorte que la question que vous avez