How to get touch position at a constant rate?
I am writing a reaction time experiment for the iPad. UIEvent / UITouch gave me some events, around 60 per seconds when the subject moves the finger around the开发者_StackOverflow社区 screen in the 'touchMoved' cycle, but unfortunately not at a constant rate. When the user stopped moving his finger, touchMoved even stops to fire events. What I need is a way, to catch the touch position at a constant rate, let say every 20 or 40 milliseconds.
And a second question is, how accurate is the timestamp of the touch event?
You can set up an NSTimer to call a method, say storeTouches, at specific intervals:
NSTimer *tUpdate;
NSTimeInterval tiCallRate = 1.0 / 60.0;
tUpdate = [NSTimer scheduledTimerWithTimeInterval:tiCallRate
target:self
selector:@selector(storeTouches:)
userInfo:nil
repeats:YES];
Then keep your own record of the current touch points that you've got. Of course, if there has been no touchesEnded event, and no touchesMoved event, then you'll know the user is still touching in exactly the same place as last time.
For 60 fps touch recording (which may be the max that the current iOS touch sensor driver allows), try to do as little as possible in the UI run loop, as this may block touch events. Check the time stamp at each touch event. If you have a fast enough UI run loop cycle, and there are much longer than frame time skips between touch moves, it's quite probable that there was no touch movement in the intervening time, so just fill in that missing data (the previous x,y point) before the current touch update.
The time stamps appear to be re-quantized to a hardware 60 fps frame rate, so don't expect any more accuracy than that.
There's no way to get every touch point when the user drags their finger. You'll only get the touch points of where the screen is being touched every time the input loop is cycled. You'll have to "predict" where the user touched for the points that you don't receive.
Adding on to this, I ran into the same problem a while ago. UIResponder Delays
精彩评论