首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >调用-renderInContext: of superlayer时CAEmitterLayer不呈现

调用-renderInContext: of superlayer时CAEmitterLayer不呈现
EN

Stack Overflow用户
提问于 2012-08-13 07:36:14
回答 2查看 1.1K关注 0票数 6

我有一个绘图应用程序,我希望我的用户能够使用粒子效果作为他们绘图的一部分。基本上,该应用程序的要点是执行自定义绘制和保存到Camera Roll或通过万维网共享。

我最近统计了CAEmitterLayer类,我认为它是添加粒子效果的一种简单而有效的方法。

我已经能够使用CAEmitterLayer实现在应用程序的屏幕上绘制粒子。所以在屏幕上渲染效果很好。

当我使用以下命令渲染绘图内容时

代码语言:javascript
复制
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的粒子效果系统库?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-08-13 07:53:00

-[CALayer renderInContext:]在一些简单的情况下很有用,但在更复杂的情况下不会像预期的那样工作。你需要找到一些其他的方法来做你的画。

The documentation for -[CALayer renderInContext:]说:

此方法的Mac v10.5实现不支持整个核心动画合成模型。不会渲染QCCompositionLayer、CAOpenGLLayer和QTMovieLayer层。此外,不会渲染使用3D变换的图层,也不会渲染指定backgroundFilters、滤镜、compositingFilter或遮罩值的图层。Mac OS X的未来版本可能会添加对渲染这些层和属性的支持。

(这些限制也适用于iOS。)

CALayer.h还说:

代码语言:javascript
复制
 * WARNING: currently this method does not implement the full
 * CoreAnimation composition model, use with caution. */
票数 4
EN

Stack Overflow用户

发布于 2016-08-11 03:08:03

我能够让我的CAEmitterLayer在其当前动画状态下正确地呈现为图像

代码语言:javascript
复制
Swift

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



Objective-C

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

在当前上下文中

代码语言:javascript
复制
UIGraphicsBeginImageContextWithOptions(size, false, 0)

并将afterScreenUpdates设置为true|YES

祝你好运:D

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11926690

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档