swift – 截图使用CAEmitterLayer查看
发布时间:2020-12-14 04:55:27 所属栏目:百科 来源:网络整理
导读:是否可以截取包含CAEmitterLayer的视图的屏幕截图? 每当我尝试时,视图都可以正常创建,但所有粒子都丢失了,这是我的代码: UIGraphicsBeginImageContext(drawingView.frame.size)var context:CGContextRef = UIGraphicsGetCurrentContext()drawingView.layer
是否可以截取包含CAEmitterLayer的视图的屏幕截图?
每当我尝试时,视图都可以正常创建,但所有粒子都丢失了,这是我的代码: UIGraphicsBeginImageContext(drawingView.frame.size) var context:CGContextRef = UIGraphicsGetCurrentContext() drawingView.layer.renderInContext(context) let image = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return image 我已经确认CAEmitterLayer在drawingView.layer上 解决方法
这适用于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 } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |