Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Screenshot View with CAEmitterLayer

Is it possible to take a screenshot of a view that includes a CAEmitterLayer?

Whenever I try, the view is created fine, but all of the particles are missing, here's my code:

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

I have confirmed that the CAEmitterLayer is on the drawingView.layer

like image 904
Chris Avatar asked Nov 09 '22 20:11

Chris


1 Answers

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
}
like image 117
Chris Avatar answered Dec 20 '22 11:12

Chris