清除 VNDocumentCameraScan 中的扫描图像缓存 Swift

Clear the scanned images cache in VNDocumentCameraScan Swift

我已经使用视觉套件进行文档扫描。我能够扫描并保存文件,但在解雇后返回此屏幕后,旧的扫描图像显示在屏幕的左下角。解散后如何清空扫描数组?

代码:

let vc = VNDocumentCameraViewController()

override func viewDidLoad() {
     super.viewDidLoad() 
     vc.delegate = self 
}

//Save button action in document VC

    func documentCameraViewController(_ controller: VNDocumentCameraViewController, didFinishWith scan: VNDocumentCameraScan) {
            print("Found \(scan.pageCount)")
            var imgArray: Array<UIImage> = []
            for i in 0 ..< scan.pageCount {
                let image = scan.imageOfPage(at: i)
                imgArray.append(image)
            }
            dismiss(animated: true) {
                self.getFileName(img: imgArray)
            }
        }

Marked the scanned images icon at the bottom left

看起来,您将 link 保存到视图控制器对象的 vc 常量中的 VNDocumentCameraViewController 实例。当您第二次显示它时,将重复使用同一个实例。

尝试像这样创建和展示它:

func showDocumentCamera() {
   let vc = VNDocumentCameraViewController()
   vc.delegate = self
   present(vc, animated: true)
}