5

是否可以截取包含 CAEmitterLayer 的视图?

每当我尝试时,视图都创建得很好,但是所有粒子都丢失了,这是我的代码:

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

我已经确认 CAEmitterLayer 在 drawingView.layer

4

1 回答 1

1

这适用于 iOS,但现在我需要类似的方法用于 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
}
于 2015-01-17T19:44:14.467 回答