是否可以拍摄包含CAEmitterLayer的视图的屏幕截图?
每当我尝试时,视图都会很好地创建,但所有粒子都会丢失,这是我的代码:
UIGraphicsBeginImageContext(drawingView.frame.size)
var context:CGContextRef = UIGraphicsGetCurrentContext()
drawingView.layer.renderInContext(context)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
我已确认CAEmitterLayer位于drawingView.layer
上答案 0 :(得分: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
}