等待所有组件加载后再渲染pdf

时间:2020-06-08 17:33:48

标签: swift

我尝试将视图渲染为pdf,但添加了MapView,问题是渲染不等待地图加载。渲染器是否可以等待并显示我想要的地图的位置?

    let pdfRenderer = UIGraphicsPDFRenderer(bounds: CGRect(x: 0, y: 0, width: width, height: height))
    DispatchQueue.main.async {
        do {
            try pdfRenderer.writePDF(to: outputFileURL, withActions: { (context) in
                context.beginPage()
                rootVC?.view.layer.render(in: context.cgContext)
            })
            print("wrote file to: \(outputFileURL.path)")
        } catch {
            print("Could not create PDF file: \(error.localizedDescription)")
        }
    }

0 个答案:

没有答案