small medium large xlarge

02 Jul 2009, 20:37
Genu T. Mathew (2 posts)


I am new to working with Core Animation and I was hoping somebody could help me.

I am trying to display two subviews (with layers) on a view in a particular order but I am unable to do it in the correct order.

One of the subviews (A) contains a single layer of polygons (drawn using NSBezierPath) while the other subview (B) has multiple layers each containing an image. I want to display subview A on top of subview B but the subview B always get displayed on top.

I have tried changing the order of adding the subviews to the main view but the result is always the same.

I have tried this before successfully on subviews without any layers. Any help is appreciated.

Thanks Genu

02 Jul 2009, 23:02
Bill Dudney (916 posts)

Hi Genu,

I would not be using subviews but instead add sublayers to your root layer.

The layer hierarchy works more or less the same way the view hierarchy does but if you are changing the layer that belongs to a view you can get into trouble.

Hope this helps.

09 Jul 2009, 16:21
Genu T. Mathew (2 posts)

Thanks for the reply Bill. I finally found a solutio to my problem.

I was using a delegate function of CALayer - (void)displayLayer:(CALayer *)layer to draw the polygons on the layer of the first subview. The problem with using this function was that I had no control over where the polygons where being drawn.

The Core Animation Cookbook at the apple website suggested using the delegate function -(void)drawLayer:inContext: whenever I wanted to draw using APKit classes like NSBezierPath. The function gave me the graphic context which I could use to draw the polygons.

The URL of the documentation is

Thanks a lot for your help.


You must be logged in to comment