2011-08-18 44 views
1

由於某種原因,我的iPad2沒有提供動作態度信息。我正在做AFAIK正是人們說要做但仍然...沒有數據。CMDeviceMotion不提供態度信息

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]; 
    } 

但是我從來沒有得到的角度。幫幫我?

回答

3

如果使用設備更新運動你只拿到的態度,即你必須呼籲initialisaiton:

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

而且stopDeviceMotionUpdates去後臺時。