I'm trying to convert my app's main view into PDF data using UIGraphicsPDFRenderer. The code sort of looks like this:
let pdfRenderer = UIGraphicsPDFRenderer()
let pdfData = pdfRenderer.pdfData { context in
context.beginPage()
view.drawHierarchy(in: view.bounds, afterScreenUpdates: true)
}
However, once I actually run this, it causes certain elements in my app to flicker every time drawHierarchy runs.

I can change afterScreenUpdates to false to prevent this, but I need the latest update of the view in order for my capture to be accurate (I am hiding a subview from being captured)
I've also tried using view.layer.render(in: context), but the resulting capture isn't accurate (missing background colors).
Is there a way to avoid the flicker? I don't want to capture the password field or keyboard, but I definitely don't want them to be flickering.
Here is a very basic reproduction of the flashing behavior. If you have input in the password field and click "capture" the password field's input will flash.

