UITapGestureRecognizer(双击)

双击,如单击,也使用 UITapGestureRecognizer。你只需将 numberOfTapsRequired 设置为 2

迅速

override func viewDidLoad() {
    super.viewDidLoad()

    // Double Tap
    let doubleTapGesture = UITapGestureRecognizer(target: self, action: #selector(handleDoubleTap))
    doubleTapGesture.numberOfTapsRequired = 2
    doubleTapView.addGestureRecognizer(doubleTapGesture)
}

// Double tap action
func handleDoubleTap() {
    label.text = "Double tap recognized"
}

笔记

  • 可在此处找到示例项目。
  • 你可以通过将 numberOfTapsRequired 设置为 3 来识别三次点击。