Я просто пишу пример кода. Надеюсь, это поможет.
Как и в приведенном ниже коде, вы можете использовать двойное и одно нажатие.
class ViewController: UIViewController {
var singleTap: UITapGestureRecognizer!
var doubleTap: UITapGestureRecognizer!
override func viewDidLoad() {
super.viewDidLoad()
doubleTap = UITapGestureRecognizer(target: self, action: #selector(tap(gesture:)))
view.addGestureRecognizer(doubleTap)
doubleTap.numberOfTapsRequired = 2
doubleTap.delaysTouchesBegan = true
singleTap = UITapGestureRecognizer(target: self, action: #selector(tap(gesture:)))
singleTap.delaysTouchesBegan = true
singleTap.require(toFail: doubleTap)
view.addGestureRecognizer(singleTap)
}
@objc
func tap(gesture: UITapGestureRecognizer) {
switch gesture {
case singleTap:
moreInfo(option: 1)
case doubleTap:
moreInfo(option: 2)
default:
print("---")
}
}
func moreInfo(option: Int) {
switch option {
case 1:
print("more information for 1")
case 2:
print("more information for 2")
default:
print("---")
}
}
}