I am building an app where I need to stack to two timed events (one within the other). I have one timer that will call a web service every 10 seconds and get new data. Between the web service calls I will animate each object I receive over 10 seconds (to bridge the gap and create a 'real-time' feel).
The amount of data I am receiving from the web service will vary and thus my animation timer needs to vary to space out the animations out over 10 seconds.
I am trying to change the timeInterval of my repeating NSTimer but can not get it to change the timeinterval when the next data set comes in.
timerDelay = 9.8/([timerAdditions count]-1);
if (!delayTimer) {
delayTimer =[NSTimer scheduledTimerWithTimeInterval:timerDelay target:self selector:@selector(delayMethod) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:delayTimer forMode:NSRunLoopCommonModes];
} else {
NSTimeInterval timeInMiliseconds = timerDelay;
NSDate *myDate =[NSDate dateWithTimeIntervalSinceNow:timeInMiliseconds];
delayTimer.fireDate = myDate;
}
The best way I've found to coordinate two timers is to have just one timer, used as a pulse. I would do something like this:
The only thing left to do is to set self.mapPointsPerFrame. Do that after each fetch. If your frame interval is 0.5s and you fetch every 10s, then the equation for that looks like this: