Last active
November 19, 2015 04:04
-
-
Save hell0again/c957c09702ccd30c9b9a to your computer and use it in GitHub Desktop.
Androidのtouchmoveとtouchend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- これまでの経緯 | |
- clickイベントは発生が遅いから自前でタップイベントを実装する | |
- 自前のタップ実装だとAndroidで反応が漏れることがたまによくある | |
- よくよく調べるとtouchmoveが1回しか発生してなかったり | |
- ひとまずOSの挙動をまねてみることにする | |
- 前提 | |
- SO-05D(Galaxy SX) | |
- Android4.1.2 | |
- タッチ位置は開発者向けオプションのポインターの位置表示オプションを使用 | |
- 端末解像度は540x960, ページの横幅は360。以下の30pxは540px中の30pxをさす。これはページサイズに換算すると20px | |
- AndroidのOSコンポーネントはこんな感じ | |
- touchstartでtargetが選択状態に | |
- touchmoveはタッチ開始位置から縦横30px以上の移動で発生。preventDefaultしなかったらそのままスクロール | |
- scrollで選択状態を解除 | |
- touchendが発生したとき、選択状態が解除されてなかったら領域判定 | |
- ただし判定領域はtarget要素のrectより上下左右に30pxづつ伸びてる | |
- touchmoveが1回しか発生しないんだけど | |
- バグなのか仕様なのか一部のAndroidではtouchmoveが1回しか発生しない。http://code.google.com/p/android/issues/detail?id=4549 | |
- touchstart, touchmoveをpreventDefaultすれば2回目以降のtouchmoveも発生するのでスクロール中にtouchmoveが発生しなくなった、ということか | |
- touchendが発生しないんだけど | |
- ↑と同じ理由なのか、touchmoveが発生してから最後にtouchendが発生するのではなく、どちらかしか発生していない模様 | |
- touchmoveっていつ発生するの | |
- タッチ開始位置から縦横に30px以上動いたときに発生。ただし縦横は独立 | |
- 30px以内の移動であればtouchmoveは発生しない | |
- iPhoneは | |
- touchstartで選択した要素の判定領域は特に伸びてない | |
- touchmoveはもっと細かい粒度で発生。スクロール発生前でも発生 | |
- touchendも毎回発生 | |
- スクロールで選択状態解除なのは共通 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment