[英]CADisplayLink in a DispatchQueue
I am trying to run a display link in a thread other than main but it simply doesn't work.我正在尝试在 main 以外的线程中运行显示链接,但它根本不起作用。 I have a simple dispatch queue created like queue = DispatchQueue(label: "xyz")
and then I create the display link as usual:我创建了一个简单的调度队列,如queue = DispatchQueue(label: "xyz")
然后我像往常一样创建显示链接:
queue.async {
self.displayLink = CADisplayLink(target: self, selector: #selector(render))
self.displayLink.add(to: .current, forMode: .common)
}
The selector never gets called.选择器永远不会被调用。 Upon checking the currentMode
of the RunLoop
I see it is nil.在检查currentMode
的RunLoop
我看到它为零。 What am I missing?我错过了什么?
Thanks谢谢
Due to the reason that your queue is non-main, the current run loop won't trigger by itself.由于您的队列是非主队列的原因,当前的运行循环不会自行触发。
You should call current.run()
manually after displayLink been added.您应该在添加 displayLink 后手动调用current.run()
。
queue.async {
self.displayLink = CADisplayLink(target: self, selector: #selector(render))
let current = RunLoop.current
self.displayLink.add(to: current, forMode: .common)
current.run()
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.