LoginSignup
1
2

More than 3 years have passed since last update.

【Swift】touchesMovedが実行される最小移動量について【Tips】

Posted at

連続的なジェスチャーの検知に使われる touchesMoved が実行されるタイミングに関して調査してみたので簡単にまとめる。

検証環境

  • Swift5.0
  • iPhone6s(iOS13.3)

検証方法

以下の様なコードでコンソールに測定した位置を出力することで検証した。

override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent) {
    let latestTouch = touches.first
    let newPoint: CGPoint = (newTouch?.location(in: view))!
// previousPointはクラスのプロパティとして保持
    let translation = CGPoint(x: previousPoint.x - newPoint.x, y: previousPoint.y - newPoint.y)
    previousPoint = newPoint
    print(translation)

実行される最小移動量

上記の検証コードを用いて上方向にまっすぐゆっくりとスクロールしていくと以下のようなログが出力される。

(0.0, 0.5)
(0.0, 0.5)
(0.0, 0.5)
(0.0, 0.5)
(0.0, 0.5)
(0.0, 0.5)

つまり、 touchesMoved が実行されるには最小で0.5ptの移動が必要、ということになる。
間違い等あればコメントをおねがいします!

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2