这是我设置AVCaptureSession进行条形码扫描的方式。
captureSession = AVCaptureSession()
guard let dev = AVCaptureDevice.default(for: .video) else { return }
guard let session = captureSession else { return }
do {
let input = try AVCaptureDeviceInput.init(device: dev)
let output = AVCaptureMetadataOutput()
if session.canAddInput(input) {
self.captureSession?.addInput(input)
}
if session.canAddOutput(output) {
session.addOutput(output)
output.setMetadataObjectsDelegate(self, queue: DispatchQueue.init(label: "scan"))
output.metadataObjectTypes = self.objectTypes
}
} catch {
}
let prevLayer = AVCaptureVideoPreviewLayer.init(session: captureSession!)
prevLayer.frame = self.view.frame
prevLayer.videoGravity = .resizeAspectFill
cameraPreview.layer.addSublayer(prevLayer)
self.captureSession?.startRunning()
问题在于某些代码仅在横向模式中被检测到。我知道可以更改预览层的方向,但是如何更改扫描到纵向的方向?