我在项目中使用加速计功能,我需要从代码中排除某些轴。我想排除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)
答案 0 :(得分:2)
如果您只想检查x轴的kThreshold以上的加速度,请更改:
if ( fabsf(acceleration.x) > kThreshold
|| fabsf(acceleration.y) > kThreshold
|| fabsf(acceleration.z) > kThreshold)
为:
if ( fabsf(acceleration.x) > kThreshold)