2
我使用的NSTimer这样如何暂停/恢复NSTIMER?
GameTimer=[NSTimer scheduledTimerWithTimeInterval:60.0/60.0 target:self selector:@selector(Move) userInfo:nil repeats:YES];
在Move方法我更新视图的位置。
-(void)Move
{
CGRect OldPosition=self.JumbleWordView.frame;
CGRect NewPosition=CGRectMake(OldPosition.origin.x, OldPosition.origin.y+MovementPerSec, OldPosition.size.width, OldPosition.size.height);
[self.JumbleWordView setFrame:NewPosition];
if (NewPosition.origin.y>=Slot_Left*CurrentBlockSize)
{
[self checkResult];
[Mytimer invalidate];
if (!isAnswerCorrect)
{
[self swapViews];
TotalRowPenalty=TotalRowPenalty+1;
Score=Score+RowIncompletePoints;
ScoreLab.text=[NSString stringWithFormat:@"%d",Score];
}
[self LoadNextWord];
}
我该如何去暂停和恢复游戏计时器?
检查这一个,不是最好的,但可以帮助你。 [计时器不暂停](http://stackoverflow.com/questions/14101880/nstimer-pause-not-working/14102886#14102886) –
您不能暂停并恢复计时器。您可以使其失效并在您再次需要时创建一个新的。
看看这里: [here](http://stackoverflow.com/questions/12171990/pause-and-resume-nstimer) – Andrea
有没有直接的方法来暂停NSTimer,但你可以保存起火日期和当前日期在使定时器无效之前。当你恢复它时,然后创建新的NSTimer对象,并将启动日期设置为先前启用的启动日期。 你也可以检查这些答案也是类似的问题。 1. [如何暂停/播放NSTimer?](http://stackoverflow.com/questions/9975562/how-to-pause-play-nstimer)2. [如何暂停和恢复NSTimer在iPhone](http:///stackoverflow.com/questions/4144242/how-to-pause-and-resume-nstimer-in-iphone)希望它可以帮助你。 –