I'm trying to render a UIView (with subviews) into a UIImage.
I'm using the new iOS 10+ UIGraphicsImageRenderer
as seen below
let renderer = UIGraphicsImageRenderer(size: view.bounds.size)
let image = renderer.image { ctx in
view.drawHierarchy(in: view.bounds, afterScreenUpdates: true)
}
But my question is how can I do this faster? I'm trying to render this UIImage before I push a new UIViewController and it has a super long delay until the UIImage is finished processing. I think this is because the renderer UIGraphicsImageRendererContext
is being created for every instantiation.
Is there any way to preload the context in the background before it needs to be used to render the image?
Or am I thinking about optimizing this wrong?
Any help would be appreciated.