我有一个滑块类(class Slider: UIControl
),它是以编程方式创建的,我想添加一个双击手势,将其调整为默认设置。不幸的是,我不能像以前在SpriteKit中那样实现UITapGestureRecognizer。
部分代码:
class Slider: UIControl{
...
let doubleTap : UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(doubleTapped))
...
init(){
...
doubleTap.numberOfTapsRequired = 1
addGestureRecognizer(doubleTap)
}
func doubleTapped(){
print("double tapped")
}
}
现在我只想实现手势识别器,然后添加我需要做的事情。我还实现了touchesMoved和touchesStarted。
最佳答案
好吧,答案很简单,不需要委托。
class Slider: UIControl{
...
init(){
...
let doubleTap : UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(doubleTapped))
doubleTap.numberOfTapsRequired = 1
addGestureRecognizer(doubleTap)
}
func doubleTapped(){
print("double tapped")
}
}