【问题标题】:Is there any way to determine the velocity of a touch motion有没有办法确定触摸运动的速度
【发布时间】:2010-01-18 19:31:22
【问题描述】:

我正在制作一个绘图应用程序,我想根据触摸速度增加画笔大小。

我将如何做到这一点?

【问题讨论】:

    标签: iphone velocity multi-touch


    【解决方案1】:

    是的。见UIView上名为touches*的方法,具体如下:

    - (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
    

    当检测到移动(“滑动”?)时调用它,并且不会被多次快速触摸“愚弄”。可以获取当前手指位置在视图中的坐标以及事件发生的时间:

    UITouch *touch = [touches anyObject];
    CGPoint inFrameCoordinate = [touch locationInView:self];
    NSTimeInterval timestamp = [touch timestamp]
    

    获取两个坐标之间的距离和时间来计算速度。

    【讨论】:

      【解决方案2】:

      嗯,UITouch 具有位置和时间戳属性;使用这些属性,您可以计算两个触摸事件之间的触摸“速度”。

      当然,这仅适用于单次触摸,您可能需要平滑结果。此外,用户可能能够通过交替用两根手指快速敲击来“愚弄”您;-)

      【讨论】:

        猜你喜欢
        • 2019-03-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-10-12
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多