【发布时间】:2017-10-08 23:36:40
【问题描述】:
好的,所以我有一个应用程序,当我按下按钮时,它会使用计时器不断振动。我还有另一个按钮,我想用它来阻止它振动。但也可以使用开始按钮再次启用。我该怎么做?这是我的代码(button2 是停止按钮)(我也在使用 xcode):
@IBAction func button1(_ sender: UIButton) {
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
_ = Timer.scheduledTimer(timeInterval: 0.0, target: self,
selector: Selector(("doaction")), userInfo: nil, repeats: true)
}
@IBAction func button2(_ sender: UIButton) {
}
【问题讨论】:
-
你做不到。您没有保留对 Timer 的任何引用(您将其分配给
_),因此您不能使其无效。那是一件非常愚蠢的事情。