I have an interesting issue involving the relationship between sibling layers in a Core Animation layer hierarchy. Here's my hierarchy:
Animation layer: <CALayer: 0x7ccf060> <--- custom animation layer
Content view's sublayers: (
"<CALayer: 0x7e7db10>", <--- map view layer
"<CALayer: 0x7cbfe10>", <--- table view layer
"<CALayer: 0x7ccf060>" <--- custom animation layer
)
So I have a few layers in a layer tree, one of which is a layer I create for an animation (which contains several sublayers, all of whose content is provide from a CGImageRef
).
Clearly, the animation layer is a sibling, not a child, of the table view layer. However, what's happening is that this custom animation layer is being offset directly proportional to the contentOffset
of the table view, i.e., how much I've scrolled. In my case, the animation layer is really an image representation of the table view.
Here's what the table view looks like scrolled down a bit just before I insert the animation layer as a sibling:
And here is immediately after, when I render the table view's layer to a CGImageRef
and use that as the source contents for a regular CALayer
's contents
property:
Again, the layer contents is merely an image representation of the table view's layer, so I don't see how the contentOffset
could affect this other layer at all. Perhaps if I was adding the layer as a sublayer of the table view's layer, maybe I could see where there would be issues. But this animation layer is a sibling layer, so why would it be affecting anything?
Here is the frame of the animation layer that I've also logged:
Animation layer's frame: {{0, 0}, {320, 372}}
I'm assuming the scrollview is doing some fancy work with layering etc to optimize rendering. Meaning that since your Animation Layer's frame is correct, it's actually fault to the rendering of the layer, which will need to be negatively offset to the scroll views offset to compensate.
When rendering first translate the Context negative to the scrollViews offset CGContextTranslateCTM(ctx, -contentOffset.x, -contentOffset.y); then render with [layer renderInContext:ctx];