【发布时间】:2017-05-10 11:56:53
【问题描述】:
我正在使用以下代码,但一直给我 0 值请检查我做错了什么
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];
感谢您的帮助
【问题讨论】:
-
任何帮助将不胜感激
-
如何初始化
self.motionManager? -
@property (nonatomic, strong) CMMotionManager *motionManager;
-
这只是一个声明,只有这个你的
motionManager将是nil -
@Losiowaty 如何做到这一点,我正在从网上获取代码...请帮助回答谢谢
标签: ios objective-c devicemotion