What's the sample rate for touchMove of Cocoa Touch?
When touch moves, touchMove is开发者_开发技巧 called by system. What's the interval between 2 moves?
The maximum sample rate, according to WWDC 2015 Session 233: Advanced Touch Input on iOS, is 60 Hz on all devices except (as of June 2015) the iPad Air 2, which samples at 120 Hz. Since the iPad Air 2 is the most recent device as of June 2015, future devices are likely to also have a 120 Hz sample rate.
Touch delivery is synchronized with screen refresh, which happens at 60 Hz on all devices. To take advantage of the iPad Air 2's higher sample rate, you must use -[UIEvent coalescedTouchesForTouch:]
.
You will receive fewer than 60 (or 120) samples per second if the touch doesn't move, or if your app takes more than 1/60th of a second to respond to events.
There is no fixed rate. The information is interrupt driven by hardware, and handled by the OS. If you write an app that simply logs the touchesMoved events, you can get a feel for it -- it is VERY fast.
If you're trying to draw, and running into a problem that finger-drawn circles come out jagged and angular, that's not a problem with touches-moved performance, that's a problem with drawing performance. If this is the problem, you should ask another question about that -- there are several tricks, largely which revolve around separating gathering the touch data and drawing it into separate threads.
To see the speed of touches moved, create a new project, and have it do NOTHING except this:
(Code typed in web browser. You may have to tweak it a little.)
static NSDate *touchReportDate = nil;
static touchMovedCount = 0;
- (void) logTouches
{
NSDate *saveDate = touchReportDate;
int saveCount = touchMovedCount;
touchReportDate = nil;
touchMovedCount = 0;
NSTimeInterval secs = -[saveDate timeIntervalSinceNow];
[saveDate release];
NSLog (@"%d touches in %0.2f seconds (%0.2f t/s)", saveCount, secs, (saveCount / secs));
}
- (void) touchesMoved: (NSSet *touches withEvent: (UIEvent*) event
{
if (touchReportDate == nil)
touchReportDate = [[NSDate date] retain];
if ([touchReportDate timeIntervalSinceNow] < -1) // report every second
{
[self logTouches]
}
}
- (void) touchesEnded: (NSSet *touches) withEvent: (UIEvent*) event
{
[self logTouches];
}
- (void) touchesCancelled: (NSSet *touches) withEvent: (UIEvent*) event
{
[self touchesEnded: touches withEvent: event];
}
精彩评论