【发布时间】:2013-04-15 05:59:20
【问题描述】:
我正在像这样使用 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];
}
如何暂停和恢复游戏计时器?
【问题讨论】:
-
您不能暂停和恢复计时器。您可以改为使其无效并在再次需要时创建一个新的。
看看这里:here -
没有暂停 NSTimer 的直接方法,但您可以在使 Timer 无效之前保存触发日期和当前日期。当您恢复它时,然后创建新的 NSTimer 对象并将触发日期设置为先前存储的触发日期。对于类似的问题,您也可以检查这些答案。 1.How to Pause/Play NSTimer? 2.how to pause and resume NSTimer in iphone 希望对你有帮助。
-
检查这个,不是最好的,但可以帮助你。 Timer not pausing
标签: ios objective-c uiview nstimer