私はすでにグーグルで他の多くの同様の質問を読んで読んだので、これがばかげた質問ではないことを願っていますが、私はこの問題を何日もいじっています。
NSTimer と UIProgressView を使用してカウントダウン タイマーを実装しましたが、この時間をさらに活用したいと考えています。つまり、タイマーが最後の 10 秒に達したときにアラート サウンドを再生します。
これが私がやったことです:
-(void) updateTimer
{
if (time <= 0.0f)
{
//Invalidate timer when time reaches 0
[timer invalidate];
[[AudioManager sharedManager] muteGameClock1Sound];
[self showGameOverViewController];
}
else
{
time -= 0.1;
[timeProgressView setProgress:time/totalTime animated:YES];
if (time < 10 && pauseView)
{
[[AudioManager sharedManager] playGameClock1Sound];
}
}
}
とでviewDidLoad
:
timeProgressView.progress = 1;
time = [ConfigFileManager sharedManager].timePerQuestion.intValue * [DatabaseManager sharedManager].numberOfQuestions;
totalTime = [ConfigFileManager sharedManager].timePerQuestion.intValue * [DatabaseManager sharedManager].numberOfQuestions;
timer = [NSTimer scheduledTimerWithTimeInterval: 0.1f target: self selector: @selector(updateTimer) userInfo: nil repeats: YES];
そしてpauseGame
方法:
-(IBAction)pauseGame:(id)sender
{
self.view.backgroundColor = [UIColor colorWithWhite: 0.0 alpha: 0.4];
pauseView = [[UIView alloc] initWithFrame: CGRectMake(0, 0, 250, 150)];
pauseView.backgroundColor = [UIColor colorWithWhite: 0.0 alpha: 0.4];
pauseView.center = CGPointMake(self.view.bounds.size.width/2, self.view.bounds.size.height/2);
pauseView.clipsToBounds = YES;
if ([pauseView.layer respondsToSelector: @selector(setCornerRadius:)])
[(id) pauseView.layer setCornerRadius: 10];
resumeButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
resumeButton.center = CGPointMake(pauseView.bounds.size.width/4, pauseView.bounds.size.height/2);
[resumeButton setBackgroundImage:[UIImage imageNamed:[ConfigFileManager sharedManager].buttonBackground] forState:UIControlStateNormal];
[resumeButton setBackgroundImage:[UIImage imageNamed:[ConfigFileManager sharedManager].buttonBackgroundSelected] forState:UIControlStateSelected];
[resumeButton setImage:[UIImage imageNamed:[ConfigFileManager sharedManager].messageResumeButton] forState:UIControlStateNormal];
[resumeButton addTarget:self action:@selector(resumeTheGame) forControlEvents:UIControlEventTouchUpInside];
restartButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
restartButton.center = CGPointMake(pauseView.bounds.size.width/2, pauseView.bounds.size.height/2);
[restartButton setBackgroundImage:[UIImage imageNamed:[ConfigFileManager sharedManager].buttonBackground] forState:UIControlStateNormal];
[restartButton setBackgroundImage:[UIImage imageNamed:[ConfigFileManager sharedManager].buttonBackgroundSelected] forState:UIControlStateSelected];
[restartButton setImage:[UIImage imageNamed:[ConfigFileManager sharedManager].messageReplayButton] forState:UIControlStateNormal];
[restartButton addTarget:self action:@selector(restartTheGame) forControlEvents:UIControlEventTouchUpInside];
quitButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
quitButton.center = CGPointMake(pauseView.bounds.size.width*3/4, pauseView.bounds.size.height/2);
[quitButton setBackgroundImage:[UIImage imageNamed:[ConfigFileManager sharedManager].buttonBackground] forState:UIControlStateNormal];
[quitButton setBackgroundImage:[UIImage imageNamed:[ConfigFileManager sharedManager].buttonBackgroundSelected] forState:UIControlStateSelected];
[quitButton setImage:[UIImage imageNamed:[ConfigFileManager sharedManager].messageQuitButton] forState:UIControlStateNormal];
[quitButton addTarget:self action:@selector(showGameOverViewController) forControlEvents:UIControlEventTouchUpInside];
[pauseView addSubview:resumeButton];
[pauseView addSubview:restartButton];
[pauseView addSubview:quitButton];
[self.view addSubview: pauseView];
choice1Button.userInteractionEnabled = NO;
choice2Button.userInteractionEnabled = NO;
choice3Button.userInteractionEnabled = NO;
choice4Button.userInteractionEnabled = NO;
choice5Button.userInteractionEnabled = NO;
pauseButton.userInteractionEnabled = NO;
}
問題は、playGameClock1Sound
メソッドがこのように呼び出されていないことですが、私が言うと、if (!pauseView && time > 10)
これは合理的ではありません。この場合、pauseButton が押されたときに is pauseView
、TRUE
メソッドplayGameClock1Sound
が再度呼び出されます。
誰かがこのばかげた問題で私を助けてくれたら本当に感謝しています。また、一時停止/再開の処理方法も教えてくれればさらに感謝します.