更改计时器的时间间隔 [英] Change the time interval of a Timer
本文介绍了更改计时器的时间间隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的问题:
是否可以在ViewDidLoad中10秒后增加 scheduledTimerWithTimeInterval:2
例如3。
例如,来自:
here is my question:
Is it possible to increase the scheduledTimerWithTimeInterval:2
for example of "3" after 10 seconds in ViewDidLoad for example.
E.g., from this:
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(createNewImage) userInfo:nil repeats:YES];
到此:
[NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(createNewImage) userInfo:nil repeats:YES];
谢谢
对不起我的英语我法语:/
thank you sorry for my english I french :/
推荐答案
像这样递归重新安排计时器:
Reschedule the timer recursively like this:
float gap = 0.50;
[NSTimer scheduledTimerWithTimeInterval:gap target:self selector:@selector(onTimer) userInfo:nil repeats:NO];
-(void) onTimer {
gap = gap + .05;
[NSTimer scheduledTimerWithTimeInterval:gap target:self selector:@selector(onTimer) userInfo:nil repeats:NO];
}
========
使其无效:
[myTimer invalidate];
然后使用新时间创建一个新的。您可能还必须先将其设置为nil。
Then create a new one with the new time. You may have to set it to nil first as well.
myTimer = nil;
myTimer = [NSTimer scheduledTimerWithTimeInterval:mySlider.value
target:self
selector:@selector(myMethod)
userInfo:nil
repeats:YES];
这篇关于更改计时器的时间间隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文