代码之家  ›  专栏  ›  技术社区  ›  Matt Long

cashaperlayer-renderinContext不工作?

  •  3
  • Matt Long  · 技术社区  · 15 年前

    我可以使用以下代码从核心动画层创建uiimage:

    - (UIImage*)contentsImage;
    {
       UIGraphicsBeginImageContext([self bounds].size);
       [self renderInContext:UIGraphicsGetCurrentContext()];
       UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
       UIGraphicsEndImageContext();
    
       return image;
    }
    

    这段代码在我的calayer派生类中。我遇到的问题是,我有两个cashapelayer,它们是我所在层的子层,不能被渲染到生成的图像中。如果我在孩子们的时候加上标准的炉管,他们就会变得很好。苹果文档说:

    呈现接收器及其子层 到指定的上下文中。

    它还说它从iPhoneOS2.0开始就有了。想知道我是否有什么东西找不到或者我应该把雷达归档。

    有什么办法可以防止孩子的现金支付员被吸引到图片上吗?

    谢谢。

    3 回复  |  直到 11 年前
        1
  •  4
  •   Regexident Amit Attias    11 年前

    calayer机器调用renderinContext来创建其位图内容属性。但是在cashapelayer中,path属性并没有实际呈现为其内容,如标题中的注释所示:

    整个形状是合成的 在层的内容及其 第一子层。

    因此renderinContext不会将cashapelayer路径实际呈现到您的上下文中。不过,我自己还没试过。

        2
  •  0
  •   kiyoshi    15 年前

    不知道它是否与您有关,但在针对renderinContext的Calayer文档中有一个注释,说明:

    **Important**: 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.

    不管怎样,我在使用uiview drawrect函数和图像上下文中的绘图时遇到了类似的问题。如果我称之为drawrect,包含子视图的整个uiview将不会绘制其子视图(这实际上是有意义的,因为它在文档中说,如果您称之为drawrect,则不管super和subview实现如何,您都要负责填充整个区域)。我解决了我的问题,只是在所有的子视图上调用drawrect,将它们传递给它们自己的框架。

    所以我建议你换掉renderincontext,用calayer的drawincontext来代替?您需要重写该方法,因为它在默认情况下不做任何事情。您的子类还需要将上下文移动到适当的框架中。为了安全起见,您可能希望检查您添加的代码是否不会影响这些层的正常呈现。

        3
  •  0
  •   Matt Long    15 年前

    我用雷达记录了这件事。我在文档中看不到它不应该工作的任何原因。如果苹果回复雷达,我会在这里回复。