我无法检测到屏幕中的双击吗?我需要打开项目中的属性吗?
所以我尝试了这个,但是不起作用:
let tapRec = UITapGestureRecognizer()
tapRec.addTarget(self, action: #selector(GameScene.doubleTap))
tapRec.numberOfTapsRequired = 2
self.view!.addGestureRecognizer(tapRec)
@objc func doubleTap(){
print ("tap")
}
答案 0 :(得分:0)
尝试一下:
let tapRec = UITapGestureRecognizer(target: self, action: #selector(handleDoubleTap(_:)))
tapRec.delegate = self
tapRec.numberOfTapsRequired = 2
view.userInteractionEnabled = true
view.addGestureRecognizer(tapRec)
然后是您的功能
extension YourViewController: UIGestureRecognizerDelegate {
func handleDoubleTap(_ gesture: UITapGestureRecognizer){
print("doubletapped")
}
}
希望这会有所帮助!