My application renders a UIView to a UIImage using the below code:
func asImage() -> UIImage {
let renderer = UIGraphicsImageRenderer(bounds: bounds)
return renderer.image { rendererContext in
self.drawHierarchy(in: bounds, afterScreenUpdates: true)
}
}
Before that code gets called, I put a loading indicator on screen that should display while the image rendering is in-progress. That indicator is an animated sequence via a UIImageView. The loading animation starts fine, but as soon as the image rendering starts, the main thread is blocked and the loading animation freezes. It hangs until the rendering in complete and then resumes. I believe both the UIImageView manipulation as well as the rendering has to happen on the main thread so I'm not sure how I can avoid the animation from freezing during this process. Thoughts?