我在方法中有以下代码:
int64_t delayInSeconds = 2.0f;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void) {
// Do some stuff
}
如果在 delayInSeconds
启动之前调用该方法,我想将计时器再延长两秒。然后执行 block 。我怎样才能做到这一点?
最佳答案
那么我建议不要为此使用 gcd。相反,您可以尝试:
[self performSelector:@selector(anyMethod) withObject:nil afterDelay:yourDelay]
//Then if you need to cancel just do:
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(anyMethod) object:nil]
//And simply reschedule your timer here.
关于ios - 延长 dispatch_after 的调度时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22183487/