DispatchQueue main 未被调用

Rod*_*ici 3 grand-central-dispatch ios swift

我有一个异步任务来执行计算和动画,当动画开始时,队列暂停,当动画完成时,队列恢复。但由于某种原因,DispatchQueue.main.sync 从未被调用。

self.someQueue = DispatchQueue(label: "Animation", qos: .background, attributes: DispatchQueue.Attributes.concurrent)
    for index in stride(from: volumeObjects.count, to: -1, by: -1) {
        mainAsyncQueue.sync{
            self.dynamicViewModel.currentPercentile = Float(index)/Float(volumeObjects.count)
            self.currentObjectIndex = index
            print(index)

            DispatchQueue.main.sync {
                UIView.animate(withDuration: 1, animations: {
                    self.updateViewModelDynamicViewModel()
                }, completion: { (finished) in
                    self.someQueue.resume()
                })
            }
            self.someQueue.suspend()
        }
    }
Run Code Online (Sandbox Code Playgroud)

这只是一个小计算,我将用它来解决比这更复杂的任务

Lou*_*nco 5

我假设这段代码位于主线程中。

如果是这样,您已同步到后台线程,并从那里尝试同步回DispatchQueue.main. 但该队列正在等待后台队列返回,然后才能执行任何操作。