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

标签 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)

最佳答案

如果您只想检查 x 轴的加速度是否超过 kThreshold,则更改:

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

到:

if ( fabsf(acceleration.x) > kThreshold)

关于ios - 如何从加速度计代码中排除特定轴?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10052467/

相关文章:

xcode - 如何让一个变量在所有场景中都已知?

iphone - 关闭 iOS 中的默认旋转动画

iphone - IOS 中的单元测试

ios - HKAnchoredObjectQuery 可以在 HealthKit 中查询已删除的 HKSampleType 吗?

ios - 使用 UITextField 保存文件

iphone - AFNetworking POST并取回数据

javascript - 是否可以在 iOS 7 Safari 中隐藏地址栏?

iphone - NSUserDefaults 在检索之前刷新数据

ios - 使用 imagePicker 时 ImageView 旋转

objective-c - 如何在 Xcode 中保护我的框架?