0
votes

I have a UIScrollView with CAShapeLayer sub layer that renders a simple line. The CAShapeLayer sublayer has its own sub CAShapeLayer. This causes scrolling and zooming to be slow. The hierarchy is like this:

-UIScrollViewLayer -CAShapeLayer -CAShapeLayer

If I change this the hierarchy so that it is only one level deep I do not have performance issues:

-UIScrollViewLayer -CAShapeLayer -CAShapeLayer

What am i doing wrong?

1
Can you explain you question a little bit more. Using nested layers could prevent those layers to be cached. That could be your problem. For more help I need to understand your problem better.Cemal Eker

1 Answers

2
votes

Cemel,

So my scroll view controller is currently doing this:

[self.uiview.layer addSublayer:myCALayer];

myCaLayer also does this in its init method:

CAShapeLayer *overlayLayer = [[CAShapeLayer alloc] init];
[self addSublayer:overlayLayer]

I have found this hierarchy to be slow for some reason. If I instead flatten the hierarchy and do this in my uiscrollview controller instead:

[self.uiview.layer addSublayer:myCALayer];
CAShapeLayer *overlayLayer = [[CAShapeLayer alloc] init];
[self.uiview.layer addSublayer:overlayLayer]

Then performance is much better. Hope that makes more sense.