View screenshot from CAEmitterLayer

Can I take a screenshot with a view that includes CAEmitterLayer?

Whenever I try, the view is created perfectly, but all the particles are missing, here is my code:

UIGraphicsBeginImageContext(drawingView.frame.size) var context:CGContextRef = UIGraphicsGetCurrentContext() drawingView.layer.renderInContext(context) let image = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return image 

I confirmed that CAEmitterLayer is in drawing.layer drawing

+5
source share
1 answer

This works for iOS, but now I need a similar method for OSX:

 func offscreenScreenshot(drawingView:UIView) -> Image { UIGraphicsBeginImageContextWithOptions(drawingView.frame.size, true, 1.0) let res = drawingView.drawViewHierarchyInRect(drawingView.bounds, afterScreenUpdates: false) let image = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return image } 
+1
source

Source: https://habr.com/ru/post/1211121/


All Articles