如何使用 SpriteKit 检查我的按钮是否被点击?

How do I check for a click on my button using SpriteKit?

我创建了一个按钮,现在我想检查对该按钮的点击,我该怎么做?我没有在我的代码中使用任何 类。下面是我用来创建按钮的代码。

let startButton = UIButton(type: .system)    
startButton.frame = CGRect(x: 300, y: 400, width: 50, height: 10)
startButton.tintColor = .blue
startButton.setTitle("Next", for:.normal)
view.addSubview(startButton)

我想我需要使用 touchesBegan 方法,但我不知道如何正确使用它。

提前致谢!

你的按钮

let startButton = UIButton(type: .system)    
startButton.frame = CGRect(x: 300, y: 400, width: 50, height: 10)
startButton.tintColor = .blue
startButton.setTitle("Next", for:.normal)
view.addSubview(startButton)

添加操作

btn.addTarget(self, action: #selector(TDquizOptionBtn.TapAction(_:)), forControlEvents: UIControlEvents.TouchUpIn边)

你的按钮操作

 func TapAction(sender:UIButton!){

      //do whatever you want to do on button action
    }