I'm tring to capture UIView or CALayer with CoreAnimation into UIImages on iOS.
this is how i capture it in UIView extension:
public func captureImage() -> UIImage?{
var image: UIImage?
UIGraphicsBeginImageContextWithOptions(bounds.size, false, UIScreen.main.scale)
if let context = UIGraphicsGetCurrentContext() {
layer.presentation()?.render(in: context)
image = UIGraphicsGetImageFromCurrentImageContext()
context.restoreGState()
}
UIGraphicsEndImageContext()
return image
}
it does not work with CoreAnimation, the images it captures are the same, without any (animation) change.
the CALayer API Document shows:
/* Renders the receiver and its sublayers into 'ctx'. This method
* renders directly from the layer tree. Renders in the coordinate space
* of the layer.
*
* WARNING: currently this method does not implement the full
* CoreAnimation composition model, use with caution. */
/** Rendering properties and methods. **/
open func render(in ctx: CGContext)
is there some way to resolve it ?