CMDeviceMotion 不提供态度信息

发布于 2024-11-30 07:17:32 字数 631 浏览 2 评论 0原文

由于某种原因,我的 iPad2 不提供运动姿态信息。我正在做据我所知正是人们所说的事情,但仍然......没有数据。

float angle = 0;
CMDeviceMotion *deviceMotion;      
CMAttitude *attitude;
deviceMotion = motionManager.deviceMotion;  
if (deviceMotion) {
    attitude = deviceMotion.attitude;

    [attitude multiplyByInverseOfAttitude:referenceAttitude];
    angle = [attitude roll];
} else {
    NSLog (@"Cannot get angles.");
}

在我的代码的前面,我这样做了:

    motionManager = [[CMMotionManager alloc] init];
    if (motionManager.gyroAvailable) {          
        [motionManager startGyroUpdates];
    } 

但是我从来没有得到角度。帮助?

For some reason my iPad2 is not providing motion attitude information. I am doing AFAIK precisely what people say to do but still... no data.

float angle = 0;
CMDeviceMotion *deviceMotion;      
CMAttitude *attitude;
deviceMotion = motionManager.deviceMotion;  
if (deviceMotion) {
    attitude = deviceMotion.attitude;

    [attitude multiplyByInverseOfAttitude:referenceAttitude];
    angle = [attitude roll];
} else {
    NSLog (@"Cannot get angles.");
}

Earlier in my code I do this:

    motionManager = [[CMMotionManager alloc] init];
    if (motionManager.gyroAvailable) {          
        [motionManager startGyroUpdates];
    } 

However I never get the angle. Help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吃兔兔 2024-12-07 07:17:32

调用initialisaiton:和stopDeviceMotionUpdates

if (![motionManager isDeviceMotionActive]) {
    [motionManager startDeviceMotionUpdates];
}

如果您使用设备运动更新,您只会获得态度,即您必须在进入后台时

You only get attitude if you use device motion updates, i.e. you have to call for initialisaiton:

if (![motionManager isDeviceMotionActive]) {
    [motionManager startDeviceMotionUpdates];
}

And stopDeviceMotionUpdates when going to background.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文