Skip to content

Render Lottie to UIImage with .coreAnimation #1769

Answered by calda
artsimonyan23 asked this question in Q&A
Discussion options

You must be logged in to vote

This is a known problem with the Core Animation rendering engine.

The CA engine animates by playing CAAnimations. These animations don't actually affect the appearance of the animation view's layer -- they only affect the appearance of the view's layer.presentation(). Because of this, the view appears blank when rendered using view.layer.render(in:).

There are two possible workarounds:

  1. Render the image using view.layer.presentation()?.render(in:) instead. The presentation layer is only available if the view is currently being rendered on-screen in a UIWindow. This is probably not a problem in most application use cases, but can be tricky in headless use cases like snapshot testing (we've…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by calda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants