我在我的项目中使用加速度计功能,我需要从代码中排除某些轴。我想排除 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/