0

I was drawing a background image in the Draw method with several paths (CGPath) over it. To avoid drawing the background image every time a setNeedDisplay is called (when a path changes), I've created a layer with the content = background image.

This layer is added when the background image is set:

Layer.InsertSublayer(backgroundLayer, 0);

And the paths are drawn in the Draw method:

   public override void Draw(RectangleF rect)
   {
    base.Draw(rect);
    using (CGContext context = UIGraphics.GetCurrentContext())
    {
      CGPath path = new CGPath();
      ...
      context.DrawPath(CGPathDrawingMode.FillStroke);  
    }
   }

It seems that the drawing of the paths is being made in the "main" Layer, that is the superlayer of the background layer that I create (this is my assumption, don't know for sure).

Is it possible to draw the shapes in a different Layer (this way I could add a second layer to the superlayer and change the sublayer zposition)?

Thanks for your help,

L. Pinho

2
  • I need a little more information than this. It looks like there is some confusion between UIKit UIView and CGAnimation's CALayer. First, the content property, is "backgroundImage" a CGImage or a UIImage? If it is a UIImage then that is the first problem. The content needs to be a CGImage. Also, you are using CGContext in the UIView's draw method. Did you intend to make a CALayer or a UIView? You don't necessarily need a second layer to change the zPosition. Although it would make everything cleaner.
    – JamWils
    Dec 19, 2013 at 17:46
  • Hi Jan, I'm using a CALayer that I add to the self.Layer, at this time I'm using a UIImage to set the content (I will change to CGImage). Yes, I'm using the Draw method of the UIView to get the CGContext to draw the paths. I want to use a 2nd layer to avoid redrawing the background image every time I change the paths drawn over it. Hope you can help me.
    – lpinho
    Dec 20, 2013 at 9:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.