Cocoa Touch touchMove的采样率是多少?

时间:2010-04-03 09:31:27

标签: iphone

触摸移动时,系统会调用touchMove。 2次移动之间的间隔是多少?

2 个答案:

答案 0 :(得分:3)

根据WWDC 2015 Session 233: Advanced Touch Input on iOS,最大采样率在所有设备上均为60 Hz(除了2015年6月),iPad Air 2采样频率为120 Hz。由于iPad Air 2是截至2015年6月的最新设备,未来的设备也可能具有120 Hz的采样率。

触摸传送与屏幕刷新同步,屏幕刷新在所有设备上以60 Hz的频率发生。要利用iPad Air 2的更高采样率,您必须使用-[UIEvent coalescedTouchesForTouch:]

如果触摸不移动,或者您的应用需要超过1/60秒才能响应事件,您每秒会收到少于60(或120)个样本。

答案 1 :(得分:2)

没有固定费率。信息由硬件中断驱动,由OS处理。如果你编写一个只记录touchesMoved事件的应用程序,你可以感受到它 - 它非常快。

如果您正在尝试绘制并遇到一个问题,即手指绘制的圆圈出现锯齿状和棱角分明,这对于触摸移动的性能来说不是问题,这是绘图性能的问题。如果这是问题,你应该问另一个问题 - 有几个技巧,主要是围绕分离收集触摸数据并将其绘制到单独的线程中。

要查看移动的触摸速度,请创建一个新项目,然后让它 NOTHING 除外:

(在网络浏览器中输入代码。您可能需要稍微调整一下。)

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];
}