【发布时间】:2023-04-11 04:33:01
【问题描述】:
我正在构建一个自定义相机,但结果很糟糕。当我尝试捕获图像时,我有时没有收到预期的委托回调。例如,这是我的委托方法:
func photoOutput(_ output: AVCapturePhotoOutput, willBeginCaptureFor resolvedSettings: AVCaptureResolvedPhotoSettings) {
print("will begin")
}
func photoOutput(_ output: AVCapturePhotoOutput, willCapturePhotoFor resolvedSettings: AVCaptureResolvedPhotoSettings) {
print("will capture")
}
func photoOutput(_ output: AVCapturePhotoOutput, didCapturePhotoFor resolvedSettings: AVCaptureResolvedPhotoSettings) {
print("did capture")
}
func photoOutput(_ output: AVCapturePhotoOutput, didFinishCaptureFor resolvedSettings: AVCaptureResolvedPhotoSettings, error: Error?) {
print("finished capture")
}
func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {
print("finish process")
}
我有一个触发以下方法的按钮:
func capture() {
print("capture called")
let settings = AVCapturePhotoSettings()
captureOutput.capturePhoto(with: settings, delegate: self)
}
每次调用此方法时,我希望控制台中的输出如下:
capture called
will begin
will capture
did capture
finish process
finished capture
image set
但是,我似乎有 50/50 的机会只能得到以下输出:
capture called
did capture
这是怎么回事?
【问题讨论】:
-
嗯,奇怪。您是否尝试过使用单独的类作为委托并为每个捕获请求创建一个新实例(如 Apple 的 AVCam 示例中)?我可以想象由于某种原因,某些东西正在阻止处理您捕获的图像......
-
有没有人能解决这个问题?我也得到了这种确切的行为。
标签: ios avfoundation avcapturesession