NSTimer选择器问题
问候!
例如,我有以下函数:
-(void) doMainBrick
{
NSTimer * timer = [NSTimer scheduledTimerWithTimeInterval:0.1
target:self
selector:@selector(dropBrick:)
userInfo:nil
repeats:YES];
}
-(void) dropBrick:(NSTimer*) timex
{
//deal something
[self SwitchBrick];
}
我想知道是否可能,如果 dropBrick
函数执行的操作超过 scheduledTimerWithTimeInterval
(在上面的示例中,它是 0.1), 另一个调用 dropBrick
再次发生(每 0.1 秒触发 dropBrick,重复:YES)? 或者无论如何,NSTimer
都会等待最后一个 dropBrick 结束然后触发?
Greeting !!
I've the following function for example :
-(void) doMainBrick
{
NSTimer * timer = [NSTimer scheduledTimerWithTimeInterval:0.1
target:self
selector:@selector(dropBrick:)
userInfo:nil
repeats:YES];
}
-(void) dropBrick:(NSTimer*) timex
{
//deal something
[self SwitchBrick];
}
I wonder if it is possible, if dropBrick
function do more than scheduledTimerWithTimeInterval
( in my sample above , it is 0.1) ,
another call dropBrick
happen again (every 0.1 sec fire dropBrick,repeats:YES)?
or no matter what, NSTimer
will wait for last dropBrick end and then fired?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
NSTimers
在 RunLoop 上调度。这意味着在 RunLoop 的每次迭代中,系统都会执行以下操作:
因此:
NSTimer
不关心您是否手动调用 dropBrick 除了计时器本身触发的调用NSTimers
are scheduled on the RunLoop.This means that at each iteration of the RunLoop, the system does the following:
As a consequence:
NSTimer
doesn't care if you call dropBrick by yourself manually in addition to the calls fired by the timer itself我能想到的一个想法是...
设置 Repeat:NO 并让 dropBrick 递归调用自身。添加一些sleep来控制递归调用的频率。
One idea i can think of is...
Set the Repeat:NO and let dropBrick recursive call itself. Add some sleep to control the frequency of recursive call.