这是我的代码:
float interval = 0.03;
while (interval > 0.005) {
timer = [NSTimer scheduledTimerWithTimeInterval:interval target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
NSLog(@"%f", interval);
interval = interval - 0.005;
}
如何让while循环在每次循环后等待一段特定的时间?我一直在搜索像sleep或者PerformSelector:withObject:afterDelay但它们既不工作也不知道如何使用它们......有些帮助吗?
答案 0 :(得分:0)
您可以使用递归结构:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
[self recursiveMethode:[NSNumber numberWithDouble:0.3]];
}
-(void)onTimer
{
NSLog(@"timer");
}
-(void)recursiveMethode:(NSNumber *)interval
{
timer = [NSTimer scheduledTimerWithTimeInterval:interval.doubleValue target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
NSLog(@"%f", interval.doubleValue);
double delay = 1;
[self performSelector:@selector(recursiveMethode:) withObject:[NSNumber numberWithDouble:interval.doubleValue - 0.05] afterDelay:delay];
}