CAEmitterLayer not rendering when -renderInContext: of superlayer is called

不羁岁月 提交于 2019-12-01 17:39:07

-[CALayer renderInContext:] is useful in a few simple cases, but will not work as expected in more complicated situations. You will need to find some other way to do your drawing.

The documentation for -[CALayer renderInContext:] says:

The Mac OS X v10.5 implementation of this method does not support the entire Core Animation composition model. QCCompositionLayer, CAOpenGLLayer, and QTMovieLayer layers are not rendered. Additionally, layers that use 3D transforms are not rendered, nor are layers that specify backgroundFilters, filters, compositingFilter, or a mask values. Future versions of Mac OS X may add support for rendering these layers and properties.

(These limitations apply to iOS, too.)

The header CALayer.h also says:

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

I was able to get my CAEmitterLayer rendered as an image correctly in its current animation state with

Swift

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



Objective-C

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

within a current context

UIGraphicsBeginImageContextWithOptions(size, false, 0)

and set afterScreenUpdates to true|YES

Good luck with that one :D

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!