1

何らかの理由で、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];
    } 

しかし、私は角度を得ることはありません。ヘルプ?

4

1 に答える 1

3

デバイスモーションの更新を使用する場合にのみ姿勢を取得します。つまり、初期化を呼び出す必要があります。

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

そしてstopDeviceMotionUpdates背景に行くとき。

于 2011-08-18T06:44:16.737 に答える