我试图构建一个应用程序,当第一次触摸屏幕时,它会启动一个NSTimer,但在触摸开始功能中使用NSTimer时,我得到了一个信号sigbart错误。如果有人有任何替代方法,我可以用得到同样的结果,我会很感激
这是我当前的基本代码
var condition = 0
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
if(condition == 1) {
timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("timerUpdate"), userInfo: nil, repeats: true)
}
cat.physicsBody?.velocity = CGVectorMake(0, 0)
cat.physicsBody?.applyImpulse(CGVectorMake(0, 1))
}
您必须为选择器添加函数timerUpdate
。
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
if(condition == 1) {
timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("timerUpdate"), userInfo: nil, repeats: true)
}
cat.physicsBody?.velocity = CGVectorMake(0, 0)
cat.physicsBody?.applyImpulse(CGVectorMake(0, 1))
}
func timerUpdate(){
print("timerUpdate")
}