如何从加速度计代码中排除特定轴?

时间:2012-04-07 06:56:56

标签: ios iphone xcode accelerometer

我在项目中使用加速计功能,我需要从代码中排除某些轴。我想排除Y& Z并且只使用X.谢谢

这是我正在使用的代码。

-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration{

    double const kThreshold = 1.5;
    //    double const kThreshold = 2.0;
    if ( fabsf(acceleration.x) > kThreshold
        || fabsf(acceleration.y) > kThreshold
        || fabsf(acceleration.z) > kThreshold)

1 个答案:

答案 0 :(得分:2)

如果您只想检查x轴的kThreshold以上的加速度,请更改:

if ( fabsf(acceleration.x) > kThreshold
        || fabsf(acceleration.y) > kThreshold
        || fabsf(acceleration.z) > kThreshold)

为:

if ( fabsf(acceleration.x) > kThreshold)