我正在使用以下代码在我的iOS应用中拍照:
self.stillImageOutput.captureStillImageAsynchronously(from: videoConnection) {
// Do some stuff here
self.captureSession.stopRunning()
// Do some more stuff
}
出于某种原因,在捕获程序段内进行stopRunning()
调用会使快门声音变得干扰。如果我将其取下,则快门声音非常好。我怎样才能防止这种情况发生?
答案 0 :(得分:3)
您不希望异步访问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 after