Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 设置时间间隔快,然后逐渐变慢_Iphone_Ios4_Nstimer_Nstimeinterval - Fatal编程技术网

Iphone 设置时间间隔快,然后逐渐变慢

Iphone 设置时间间隔快,然后逐渐变慢,iphone,ios4,nstimer,nstimeinterval,Iphone,Ios4,Nstimer,Nstimeinterval,我有以下代码: 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 } 我想打电话给时间为0.50,然后0.5

我有以下代码:

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
}
我想打电话给时间为0.50,然后0.55,然后0.60&很快。这意味着先快后慢

问题是每次调用ontimer的时间为0.50秒


提前感谢。

您是否尝试过将时间变量设置为静态?

如果计时器已启动,则无法调整时间间隔,因此每次都必须更改fireDate。像这样:

- (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];

你为什么不编辑原始问题以使其更清楚?好的,现在我会处理它的。谢谢,它对我很好。问题是我没有使用静态NSTimeInterval。在使用静态NSTimeInterval之后,我的问题现在已经解决了。谢谢。