What is the best approach to changing view properties due to accelerometer changes?

I want to do this: if the device moves (accelerometer values ​​change), then I want to adjust some values ​​in my view according to this movement.

I would like to call a method every time the accelerometer value changes? I think this would be a bad idea as they might be updated too often.

0


source to share


4 answers


If you are worried about changing too often, just use the battery; use some code that detects changes and checks the system time; only if enough system time has passed do you run the method (potentially accumulated).



+1


source


I think so ... If not, you only have one option. Read periodically. Reduce the period again, increase the accuracy. Thus, it may be more efficient if you can trigger an event when a value change is detected.



+1


source


If you're worried about noise coming from the accelerometer, you can smooth out the inputs by implementing a moving average. This will allow you to take the samples you often need without worrying about false accelerometer triggers.

http://en.wikipedia.org/wiki/Moving_average

+1


source


When you implement the method accelerometer:didAccelerate:

in UIAccelerometerDelegate

, just specify a statement if

, checking if there is enough time between the last time you received the update, long enough.

In your class that implements UIAccelerometerDelegate

, you can have a property that contains something like lastTimeUpdated

, and then update it whenever you change the view

+1


source







All Articles