开发者

How can you measure speed at which the user is moving their finger across the iPhone/iPad screen?

I'm diving into iPhone development and I'm trying to get my head around gestures and the touch events. How can I measure how fast the user is moving their finger across the screen of an iOS devi开发者_高级运维ce using the touche events (touchesBegan, touchesMoved, etc)?

Thanks so much in advance for your help!


You can do that by using the timestamp property of UITouch class. The property is described as:

The value of this property is the time, in seconds, since system startup the touch either originated or was last changed. You can store and compare the initial value of this attribute to subsequent timestamp values of the UITouch instance to determine the duration of the touch and, if it is being swiped, the speed of movement.

UITouch Class Reference


Save time and position of the lasst event and you can calculate the speed (newpos-old) / timediff. The new gesture recognizers have some velocity support as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜