Question

What i want to do is record the time of when a button has been pressed. All these times will be stored in an array. The program will then run through the array and look at the time values and then highlight the button states at those particular times during playback.

Hopefully this makes sense, whats the best way to do this?! Thanks in advance.

------------------ MORE DETAIL ------------------

the first thing that came up on my mind was... 'ah ha, timestamp', but then looking into the documentation, in a certain section in the timestamp page somewhere in the paragraph it states the following:

....You should not use it to determine the exact time at which the event occurred but should instead compare it to the timestamp of another acceleration event to determine the elapsed time between the events....

this is not great.. as i am assuming that it will not be accurate when it comes to playback of highlighting the buttons at the exact times of when the user had actually pressed them during record. Please let me know of what i should use and do.

Was it helpful?

Solution

You can use CFAbsoluteTimeGetCurrent() to get the current time expressed as the number of seconds (as a double value, so fractional seconds will be there) since January 1, 2001 00:00:00 GMT.

Hence, you should record the value of CFAbsoluteTimeGetCurrent() at some point when your app starts, and then record its value every time a button is pressed. Then, by subtracting the time the app started from the time the button was pressed gives you the number of seconds the button was pressed since the app started. You can then play back the button presses at a later time by taking that time delta and adding it to the time when playback started.

OTHER TIPS

The -[UIEvent timestamp] property will be the most accurate representation of when the touch actually occurred. If you use CFAbsoluteTimeGetCurrent() or the UNIX time() functions you will get the current time the moment function is called, not when the event actually occurred (which will be sometime earlier).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top