3

I want to overlay a large CATiledLayer with some vector drawing. To get started I'd like to use CAShapeLayer, which is to be replaced by some custom CALayer subclass or delegate.

The good part is that it works. However, I get this warning on every redraw:

-[<CAShapeLayer: 0x1700daa0> display]: Ignoring bogus layer size (150000.000000, 150000.000000), contentsScale 1.000000, backing store size (150000.000000, 150000.000000)

How do I get rid of this warning properly?

I figure I don't need a backing store, since the whole point of this layer is that it only (and continuously) draws the visible part of the layer.

One (accidentally discovered) way to prevent this error is to set layer.contentsScale to a small value or even zero, so the backing store will not have a "bogus sized" backing store. (this property is normally used to allow @2x/@3x devices to have a high-res backing store)

But this feels like a hack that will break my app some day. So how can I disable the backing store for a CALayer?

CATiledLayer (a subclass CALayer) doesn't give such a warning, despite having the same size. I've looked into subclassing CALayer or CAShapeLayer, trying to replicate CAShapeLayer, but this is quite confusing. CAShapeLayer doesn't seem to play by the same rules as me; my drawInContext: renders vectors pixelated while the layer draws its own vectors crisp, even within the same CALayer. The almost-undocumented layer.contents property only refers to a backing store for my pixelated lines.

Is it even possible to re-create CAShapeLayer with the public API?

mvds
  • 45,755
  • 8
  • 102
  • 111
  • Unfortunately I guess that the layer you want to use is too big and not supported, that is why CATiledLayer exist – Andrea May 07 '15 at 19:00
  • You can't possibly show a drawing that big, so what are you _really_ trying to do? Also, why do you need CAShapeLayer when you can just draw? – matt May 09 '15 at 20:41
  • "The almost-undocumented layer.contents property" There is nothing undocumented about it. It is very well documented. – matt May 09 '15 at 20:42
  • @matt a pointer would be nice ;-) I didn't get much further than that its type is `id` and that you can assign a `CGImageRef` to it (iOS CALayer class reference). – mvds May 09 '15 at 20:57
  • There is nothing else to know! – matt May 09 '15 at 21:03
  • @matt I don't think it really matters what I'm drawing. Point is I have a huge bitmap drawing (CATiledLayer) and I want to overlay it with vector drawing. I used to draw the vectors in the CATiledLayer, but I don't like the sight of my vectors being part of the tiling process. E.g. the line thickness should be constant on screen and not jigsaw when zooming in and out, and the effect of tile caching is horrible on vectors. Then, drawing in the same coordinate system is a big plus, so that's why I like the idea of having a layer exactly aligned with the CATiledLayer and only drawing whatever ... – mvds May 09 '15 at 21:04
  • ... needs to be on screen at the moment of drawing. CAShapeLayer seems to do just that, so that's why I thought it would be a good start to replicate its behavior. The "bogus layer size" warning is a red flag, I can't ship code which emits 60 loglines per second (for various reasons), so before deciding on using my `contentsScale` hack, I'm trying to get some more understanding of all this. – mvds May 09 '15 at 21:07
  • @matt I am also getting this same thing! I've a image size of (8681.000000, 3508.000000) contentsScale 3.000000, backing store size (26043.000000, 10524.000000), it's just ignore the layer! – Rashad Nov 30 '20 at 16:56

0 Answers0