Re: Guidance on CATiledLayer
Re: Guidance on CATiledLayer
- Subject: Re: Guidance on CATiledLayer
- From: David Duncan <email@hidden>
- Date: Mon, 31 Dec 2012 14:03:28 -0800
On Dec 29, 2012, at 8:48 PM, Graham Cox <email@hidden> wrote:
> I'm just looking for a bit of general guidance/encouragement regarding the use of CATiledLayer
>
> I have a view which is layer hosting and I'm using layers to represent many small items in the view. That's all fine, but I also want to have a grid in the background (like graph paper). I've implemented that using CAShapeLayer currently and it works fine, as long as the layer doesn't get too big. However, the layer can get large when the view is zoomed in, or just given a large bounds - I run into errors logged about a surface being too large (presumably the OpenGL textures generated by the layer exceed some internal limit).
>
> In looking for a solution, I came across CATiledLayer, which appears to offer a solution, since the graph paper has generally the same appearance everywhere. But it's not that clear from documentation whether it's the right tool for the job. The layer itself needs to be the size of the view and the view's frame can get large with zooming. Is that how CATiledLayer works? It allows the layer frame to be as large as you like and tiles its content to fit?
>
> I will proceed to experiment but if anyone has any experience of this I would welcome any encouraging (or otherwise) remarks.
I think your best bet is still to use a CAShapeLayer, but to combine it with 2 CAReplicatorLayers. The only trick here is to ensure that you manage the number of replications for each of the replicators correctly so that you get the effect you want.
The shape layer is the root shape (and using a shape layer in this case so you maintain the crispness that you are looking for, otherwise I would just use an image). Each of the replicator layers are for replicating in a single dimension. Setup the instance transform of the replicators as appropriate to tile the children horizontally or vertically. Replicator 1 has a single child, Replicator 2 which has a single child, the Shape Layer (all layers added to a replicator are replicated).
That should give you your grid background.
--
David Duncan
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden