我有一个使用计时器的游戏。我想这样做,以便用户可以选择一个按钮并暂停该计时器,当他们再次单击该按钮时,它将取消暂停该计时器。我已经有了定时器的代码,只需要一些帮助来暂停定时器和双动作按钮。
定时器代码:
-(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];
}
}