0

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?

Imran
  • 1,488
  • 1
  • 15
  • 36
  • 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 Jun 25 '12 at 14:36

1 Answers1

2

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.

Imran
  • 1,488
  • 1
  • 15
  • 36
  • One more thing i am setting the path property on the shapelayers i just havent shown this above for simplicity. – Imran Jun 25 '12 at 14:48
  • Hmm so i tried setting layer.ShouldRasterize as i thought it would improve performance but when i look at instrumentation it looks like it redraws everytime the scrollview scrolls. Not sure if I understood the behaviour properly or if I did something wrong. – Imran Jun 25 '12 at 16:55