Detect iPhone screen orientation

你。 提交于 2019-11-28 07:51:25

I think your problem is that you're using int variables when you want float.

I think the accelerationX and –Y should be instance variables and thus:

accelerationX = acceleration.x * kfilteringFactor + accelerationX * (1.0 - kfilteringFactor);
accelerationY = acceleration.y * kfilteringFactor + accelerationY * (1.0 - kfilteringFactor);

Should give you more what you were looking for.

The reason is that you're using local variables, while they shouldn't be local.

Try to do the following:

Declare instance variables:

@interface YourViewControllerClass: UIViewController {
    float accelerationX, accelerationY;
}

...

other declarations

Update variables in accelerometer delegate:

 accelerationX = acceleration.x * kfilteringFactor + accelerationX * (1.0 - kfilteringFactor);
 accelerationY = acceleration.y * kfilteringFactor + accelerationY * (1.0 - kfilteringFactor);

It should give more precise results without sudden jumps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!