我有一个使用倒数计时器的游戏,当计时器到时,您会看到游戏概览。我想添加一个功能,如果他们点击一个按钮,它会为计时器增加 1、2 或 3 秒。我已经有了计时器的代码(如下),但我只需要知道如何为计数器添加更多时间。我想到了,我不得不说视图何时切换,并且需要计算增加的时间。
代码:
-(IBAction)Ready:(id)sender {
[self performSelector:@selector(TimerDelay) withObject:nil afterDelay:1.0];
[self performSelector:@selector(delay) withObject:nil afterDelay:36.5];
}
-(void)TimerDelay {
MainInt = 36;
timer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(countDownDuration)
userInfo:nil
repeats:YES];
if (timer == 0)
{
[timer invalidate];
}
}
-(void)countDownDuration {
MainInt -= 1;
seconds.text = [NSString stringWithFormat:@"%i", MainInt];
}
-(void)delay {
GameOverView1_4inch *second= [self.storyboard instantiateViewControllerWithIdentifier:@"GameOverView1"];
second.finalScore = self.currentScore;
[self presentViewController:second animated:YES completion:nil];
}