我有一个使用计时器的游戏。我想让用户可以选择一个按钮来暂停计时器,当他们再次点击该按钮时,计时器将恢复。我已经有了计时器的代码,只需要一些帮助来实现暂停计时器和双动作按钮。
计时器的代码:
-(void)timerDelay {
mainInt = 36;
timer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(countDownDuration)
userInfo:nil
repeats:YES];
}
-(void)countDownDuration {
MainInt -= 1;
seconds.text = [NSString stringWithFormat:@"%i", MainInt];
if (MainInt <= 0) {
[timer invalidate];
[self delay];
}
}