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
來識別三次點選。