Created
June 13, 2015 04:55
-
-
Save jebai0521/a29e4225c89b5f6a23f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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