是否需要设置任何属性以允许双击(快速)

时间:2019-03-30 09:18:32

标签: ios swift sprite-kit

我无法检测到屏幕中的双击吗?我需要打开项目中的属性吗?

所以我尝试了这个,但是不起作用:

let tapRec = UITapGestureRecognizer()

tapRec.addTarget(self, action: #selector(GameScene.doubleTap))
tapRec.numberOfTapsRequired = 2
self.view!.addGestureRecognizer(tapRec)



@objc func doubleTap(){
   print ("tap")
}

1 个答案:

答案 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")
    }
}

希望这会有所帮助!