我正在使用以下代码在我的iOS应用程序中拍照:
self.stillImageOutput.captureStillImageAsynchronously(from: videoConnection) {
// Do some stuff here
self.captureSession.stopRunning()
// Do some more stuff
}由于某些原因,在捕获块中调用stopRunning()会使快门声音卡顿。如果我把它取下来,快门的声音就完全没问题了。我如何才能防止这种情况发生?
发布于 2016-10-17 21:00:23
您不希望异步访问UI。根据您的描述,听起来异步块可能是卡顿的根源。你可以尝试两种方法来让主队列播放你的声音:
// everything is going swimmingly until you play the sound...
// grab the main queue
DispatchQueue.main.async {
// play your sound
}
// and live happily ever after另一种方法:
// everything is going swimmingly until you play the sound...
// grab the main queue
DispatchQueue.main.suspend()
// play your sound
DispatchQueue.main.resume()
// and live happily ever afterhttps://stackoverflow.com/questions/40086943
复制相似问题