在我的应用程序中,我实现了 NSTimer 来计算时间。我有滑动检测,当用户在屏幕上滑动时,动画会连续运行。我的问题是当我在屏幕上滑动时(左/右连续) NSTimer 减慢。谁能告诉我如何解决这个问题?
//代码
gameTimer = [NSTimer scheduledTimerWithTimeInterval:1.0/100
target:self
selector:@selector(updateGameTimer)
userInfo:nil
repeats:YES];
-(void)updateGameTimer
{
counter++;
tick++;
if(tick==100){
tick = 0;
seconds += 1;
}
if(counter==100){
counter = 0;
}
timerLabel.text = [NSString stringWithFormat:@"%i.%02d",seconds,counter];
}
//swipe detection
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
[super touchesMoved:touches withEvent:event];
UITouch *touch = [touches anyObject];
//CGPoint curPt = [touch locationInView:self.view];
CGPoint newLocation = [touch locationInView:self.view];
CGPoint oldLocation = [touch previousLocationInView:self.view];
gameView.multipleTouchEnabled = true;
if(newLocation.x-oldLocation.x>0){
swipe_direction = 1;
//NSLog(@"left");
}
else{
swipe_direction = 2;
//NSLog(@"right");
}
if(swipe_direction==1){
//animate images
//play sound effect
}
else if(swipe_direction==2){
//animate images
//play sound effect
}
}