0

i have the following code:

xx=0.50;
[NSTimer scheduledTimerWithTimeInterval:xx target:self selector:@selector(ontimer:) userInfo:nil repeats:YES];

-(void)ontimer
{
    xx=xx+0.05;
    NSTimeInterval dt = [timer timeInterval];
    // do something
}

I want to call ontimer for 0.50 then 0.55 then 0.60 & soon. that means First Fast then gradually slow down.

The Problem is each Time ontimer will be called for 0.50 seconds.

Thanks in Advance.

Matthias Bauch
  • 89,811
  • 20
  • 225
  • 247
Hardik Patel
  • 937
  • 3
  • 14
  • 39
  • Possible duplicate of [How do I change timing for NSTimer?](http://stackoverflow.com/questions/4152097/how-do-i-change-timing-for-nstimer) Why don’t you edit the original question to make it more clear? – zoul Nov 11 '10 at 09:24
  • okey, Now onwards i will take care of it. – Hardik Patel Nov 11 '10 at 12:04

2 Answers2

1

afaik you can't adjust the timeInterval when a timer has been started, so you have to change the fireDate each time. Like this:

- (void)someTimerMethod:(NSTimer *)aTimer {
    static NSTimeInterval pause = 0.5;
    pause += 0.05;
    [aTimer setFireDate:[[[NSDate alloc] initWithTimeIntervalSinceNow:pause] autorelease]];
}

[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(someTimerMethod:) userInfo:nil repeats:YES];
Matthias Bauch
  • 89,811
  • 20
  • 225
  • 247
0

Have you tried setting your time variable to static?

Beaker
  • 1,633
  • 13
  • 22