简体   繁体   English

防止Android中的触摸事件延迟

[英]Preventing lag on touch events in Android

I'm building a Phonegap-based Android/iOS app. 我正在构建一个基于Phonegap的Android / iOS应用。 The app is supposed to detect swipes from the user. 该应用程序应该能够检测到用户的滑动。

On Android, when detecting the gestures, the app consistently displays delay of approximately 200ms before executing my code. 在Android上,当检测到手势时,该应用在执行我的代码之前始终显示大约200毫秒的延迟。

Reading around, I learned that this delay might be caused by how Android distinguishes swipes from normal taps. 到处阅读,我了解到这种延迟可能是由于Android如何区分滑动和正常点击而引起的。 If you call e.preventDefault() before 200ms have elapsed since the touch, WebKit will let you handle it as a swipe. 如果从触摸开始经过e.preventDefault()之前调用e.preventDefault() ,WebKit将允许您将其作为滑动来处理。

Question: 题:
Is there a way to completely remove this delay and force WebKit to assume the event is a swipe, thus removing the delay? 有没有一种方法可以完全消除此延迟并强制WebKit假定事件是轻扫,从而消除此延迟?

Actually, the delay is around 300ms and in this article [1], the reason why browser OEMs implemented this behaviour is given. 实际上,延迟约为300ms,在本文[1]中,给出了浏览器OEM实施此行为的原因。 There is a library called fastclick [2] that you can use to prevent this. 有一个名为fastclick [2]的库可以用来防止这种情况。 Personally, I'm using polymer gestures which has a much broader scope but holistically solves the problem of detecting gestures and preventing the 300ms delay. 就个人而言,我正在使用范围更广的高分子手势,但从整体上解决了检测手势防止300ms延迟的问题。

[1] http://updates.html5rocks.com/2013/12/300ms-tap-delay-gone-away [1] http://updates.html5rocks.com/2013/12/300ms-tap-delay-gone-away

[2] https://github.com/ftlabs/fastclick [2] https://github.com/ftlabs/fastclick

[3] https://github.com/Polymer/polymer-gestures [3] https://github.com/Polymer/polymer-gestures

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

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