简体   繁体   English

Cocoa Touch touchMove的采样率是多少?

[英]What's the sample rate for touchMove of Cocoa Touch?

When touch moves, touchMove is called by system. 触摸移动时,系统会调用touchMove。 What's the interval between 2 moves? 2次移动之间的间隔是多少?

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. 根据WWDC 2015 Session 233:iOS上的高级触摸输入,最大采样率在所有设备上均为60 Hz,除了(截至2015年6月)iPad Air 2,其采样频率为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. 由于iPad Air 2是截至2015年6月的最新设备,未来的设备也可能具有120 Hz的采样率。

Touch delivery is synchronized with screen refresh, which happens at 60 Hz on all devices. 触摸传送与屏幕刷新同步,屏幕刷新在所有设备上以60 Hz的频率发生。 To take advantage of the iPad Air 2's higher sample rate, you must use -[UIEvent coalescedTouchesForTouch:] . 要利用iPad Air 2的更高采样率,您必须使用-[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. 如果触摸不动,或者您的应用需要超过1/60秒来响应事件,您每秒将收到少于60(或120)个样本。

There is no fixed rate. 没有固定利率。 The information is interrupt driven by hardware, and handled by the OS. 信息由硬件中断驱动,由OS处理。 If you write an app that simply logs the touchesMoved events, you can get a feel for it -- it is VERY fast. 如果你编写一个只记录touchesMoved事件的应用程序,你可以感受到它 - 它非常快。

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.) (在Web浏览器中键入的代码。您可能需要稍微调整一下。)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM