开发者

CALayers not showing when drawn the first time

I've been struggling with a strange problem which has arisen in using the CorePlot framework, but which I suspect isn't an error in the framework itself. I'm hoping somebody here will have seen something similar, and can point me in a productive direction.

I have a tabbed view in which graphs are shown. The tab that is initially active has no problems at all, but often when I open the next tab, I see the following:

CALayers not showing when drawn the first time

Note that on the top graph, several labels are missing. If I switch back to the original tab, then to the second tab again, all is well every time. I've placed various diagnostic logging statements in and have determined that:

  1. The view is awake before the graph is created; and
  2. The drawInContext: method of each lab开发者_C百科el is being called, including those that are missing. In fact, the axis labels are amongst the last things rendered, so I'd expect them to show if anything does, and some of the labels that are missing are being rendered after (and before) those that are present.

Because the rendering seems to be going ahead as it should, and because this thing draws fine "the second time around", I suspect that the problem is in how I'm hooking this up to the views, or in my timing there, and not in Core Plot itself (or, for example, in clipping). I'm out of ideas on how to debug this, though, and would love to hear from anybody who has experience with a similar problem.

Thanks!


Six years later and I dealt with the same exact problem. When creating a layer, the first time around it might not yet be drawn on screen when it's needed in an animation. The second time around it is.

The simple fix is to call .layoutIfNeeded() on the layer you're trying to draw right after you add it to its super layer.


The CALayer might not be caching the content in time before the CALayer is actually getting drawn.

Without seeing the code, I would suggest to try calling -setNeedsDisplay for the CALayer that is missing the label information as soon as you have changed the content for that CALayer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜