Skip to content

Instantly share code, notes, and snippets.

@jebai0521
Created June 13, 2015 04:55
Show Gist options
  • Save jebai0521/a29e4225c89b5f6a23f1 to your computer and use it in GitHub Desktop.
Save jebai0521/a29e4225c89b5f6a23f1 to your computer and use it in GitHub Desktop.
[self.motionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue currentQueue] withHandler:^(CMDeviceMotion *motion,NSError *error){
double gravityX = motion.gravity.x;
double gravityY = motion.gravity.y;
double gravityZ = motion.gravity.z;
NSLog(@"gravityX = %f",gravityX);
NSLog(@"gravityY = %f",gravityY);
NSLog(@"gravityZ = %f",gravityZ);
double zTheta =atan2(gravityZ, sqrtf(gravityX*gravityX+gravityY*gravityY))/M_PI*180.0;
double xTheta =atan2(gravityX, sqrtf(pow(gravityY, 2)+pow(gravityZ, 2)))/M_PI*180.0;
double yTheta =atan2(gravityY, sqrtf(pow(gravityX, 2)+pow(gravityZ, 2)))/M_PI*180.0;
NSLog(@"获取手机的倾斜角度 zTheta = %f",zTheta);
NSLog(@"获取手机的倾斜角度 xTheta = %f",xTheta);
NSLog(@"获取手机的倾斜角度 yTheta = %f",yTheta);
self.z = zTheta;
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment