我在里面有一个OperationQ和for循环。在此for循环内,每次for循环迭代发生时,延迟增加后,我将调用dispatch_。这是为了确保在for循环内发生的事情会延迟并顺序发生。
现在,当我想用新数据重置此OperationQ时。我取消了operationQ的所有操作。这会取消操作,但是在抛出带有调度计时器的调度后仍在运行。我可以在operationQ内取消dispatch_after吗?
OperationQ addoperationWithBlock({
mainQ addOperationwithBlock({
// Do some UI work
delayCOnstant
for (iteration)
{
delay += delayCOnstant
dipathTime = dispatch_timeNow + delay
dispatch_after(time, mainQ,
{
// UI Drawing, dispatch after will draw smoothly and sequence
})
}
})
})
当我取消OperationQ时,该操作停止,但dispatch_after仍在使用我们给出的dispatch_time运行。任何想法或建议
最佳答案
dispatch_after
没有取消机制。能够取消是NSOperationQueue
的优点之一。因此,与其直接在您的dispatch_after
块中进行工作,不如使用该块安排一个NSOperation
,然后也可以将其取消。
关于ios - 如何使用for循环和dispatch_after取消操作队列,并增加延迟,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37058466/