我在自定义 UIView 中创建捕获 session 时遇到问题。我这样设置委托(delegate)
class Camera: UIView, AVCaptureFileOutputRecordingDelegate, AVAudioRecorderDelegate {
}
然后我设置所有内容并像这样设置委托(delegate)
self.recordingDelegate? = self
captureSession.sessionPreset = AVCaptureSessionPresetHigh
let devices = AVCaptureDevice.devices()
for device in devices {
if (device.hasMediaType(AVMediaTypeVideo)) {
if(device.position == AVCaptureDevicePosition.Back) {
captureDevice = device as? AVCaptureDevice
if captureDevice != nil {
beginSession()
}
}
}
}
一切顺利。然而,在beginSession函数中:
func beginSession() {
let err : NSError? = nil
do {
self.captureSession.addInput(try AVCaptureDeviceInput(device: self.captureDevice!))
}
catch {
print("dang")
}
if err != nil {
print("error: \(err?.localizedDescription)")
}
...
当我尝试添加捕获设备输入时抛出捕获,但它没有被添加,我不明白为什么。
我当前使用的所有代码在我将其放在 UIViewController 中之前都工作正常,但是当我将其切换到 UIView 的子类时,它停止工作。如果需要更多代码,请告诉我,任何帮助将不胜感激!
最佳答案
我发现我使用的iOS设备由于某种原因没有启用相机,因为无法添加输入,这使得预览层无法捕获任何数据
关于ios - 是否可以将 AVCaptureFileOutputRecordingDelegate 添加到子类 UIView 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37556728/