CALayers not displayed when first displayed

I struggled with a strange problem that occurred while using the CorePlot infrastructure, but I suspect that this is not a mistake in the structure itself. I hope someone here sees something similar, and can point me in a productive direction.

I have a tab that displays graphs. A bookmark that is initially active has no problems at all, but often, when I open the next tab, I see the following:

http://imgur.com/J0VDs.png

Please note that there are several labels in the upper graph. If I go back to the original tab and then to the second tab, everything will be fine every time. I put various diagnostic log entries and determined that:

  • The view is inactive until the graph is created; and
  • The drawInContext method is called: the method of each label, including those that are missing. In fact, axis labels refer to the last things displayed, so I expect them to show that something will happen, and some of the missing labels will appear after (and before) those that are present.

Since the rendering seems to be going forward, as it should be, and because this thing looks great "the second time", I suspect the problem is how I connect this to the views or in my time there, rather than in the kernel itself (or, for example, in cropping). I have no ideas on how to debug this, and would like to hear from anyone who has experience with a similar problem.

Thanks!

+4
source share
2 answers

Six years later, and I faced the same exact problem. When creating a layer for the first time around it, it may not yet be displayed on the screen when it is needed in the animation. Second time around.

A simple solution is to call .layoutIfNeeded() on the layer you are trying to draw, immediately after adding it to your super layer.

0
source

CALayer may not cache content on time before CALayer is drawn.

Without looking at the code, I would suggest trying - setNeedsDisplay for CALayer , which has no label information as soon as you change the contents of this CALayer.

0
source

All Articles