-->

superlayer被称为:当-renderInContext CAEmitterLayer不渲染(

2019-06-27 00:37发布

我有一个绘图应用程序,我想为我的用户能够使用粒子效果的绘图的一部分。 基本上,应用程序的关键是要进行自定义绘制并保存到相机胶卷或份额超过万维网。

我对中遇到CAEmitterLayer最近类,我认为将是一个简单而有效的方式来增加粒子效果。

我已经能够在屏幕上绘制粒子在使用应用程序CAEmitterLayer实施。 所以呈现在屏幕上正常工作。

当我去使用的渲染图的内容

CGContextRef context = UIGraphicsBeginImageContextWithSize(self.bounds.size);

// The instance drawingView has a CAEmitterLayer instance in its layer/view hierarchy
[drawingView.layer renderInContext:context];


//Note: I have also tried using the layer.presentationLayer and still nada

....
//Get the image from the current image context here for saving to Camera Roll or sharing


....the particles are never rendered in the image.

我认为正在发生的

CAEmitterLayer是“动画”的颗粒的恒定状态。 这就是为什么当我试图渲染层(我也试图使layers.presentationLayer和modelLayer),动画是从未犯过等戏外图像渲染不含颗粒。

问有没有人渲染的内容CAEmitterLayer屏幕外? 如果是的话,你怎么办呢?

备选问题有谁知道,请不要使用OpenGL和没有任何的cocos2d粒子特效系统库的?

Answer 1:

-[CALayer renderInContext:]是在一些简单的情况下非常有用,但预计将在更复杂的情况将无法正常工作。 你需要找到一些其他的方式做您的绘图。

对于文档-[CALayer renderInContext:]说:

这种方法的的Mac OS X v10.5的实现不支持整个Core Animation的组合模型。 QCCompositionLayer,CAOpenGLLayer和QTMovieLayer层不会呈现。 此外,使用3D变换层未呈现,也不是指定backgroundFilters,过滤器,compositingFilter或掩码值的层。 的Mac OS X的未来版本可能会增加对渲染这些层和属性的支持。

(这些限制适用于iOS的了。)

CALayer.h也说:

 * WARNING: currently this method does not implement the full
 * CoreAnimation composition model, use with caution. */


Answer 2:

我能得到我的CAEmitterLayer在当前动画状态正确地呈现为图像与

Swift

func drawViewHierarchyInRect(_ rect: CGRect,
          afterScreenUpdates afterUpdates: Bool) -> Bool



Objective-C

- (BOOL)drawViewHierarchyInRect:(CGRect)rect
             afterScreenUpdates:(BOOL)afterUpdates

当前上下文中

UIGraphicsBeginImageContextWithOptions(size, false, 0)

并设置afterScreenUpdates为true | YES

祝你好运之一:d



文章来源: CAEmitterLayer not rendering when -renderInContext: of superlayer is called