Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the magic behind CAReplicatorLayer?

What I find interesting with CAReplicatorLayer:

  • It is able to display a CALayer multiple times with different transforms very efficiently (how?)
  • It seems like it somehow reuses the "backing store" for the replicated layer and even apply some color tints to it (how?)

I would like to get hands on either the source code or get some knowledge of the magic behind CAReplicatorLayer. I would like to have a CALayer class similar to CAReplicatorLayer, but with more control. I would like to have control on the transform individually for each replicated instance.

So asked in a totally different manner: is it possible to get the "backing store" for a CALayer and display it however I want as many times I want?

(by "backing store" I mean the rendered texture for the CALayer/UIView. I don't know much about what's happening under the hoods of CoreAnimation/QuartzCore).


Why I'm not looking at alternatives like e.g. rendering the CALayer to a UIImage:

  • Performance
  • Content is dynamic/changing pretty frequently under the transitions
  • It would be hands down awesome to do it the other way!
like image 655
hfossli Avatar asked Dec 12 '12 14:12

hfossli


People also ask

How do you make a CALayer?

You can create a new CALayer very easily with the following line of code: CALayer *sublayer = [CALayer layer]; Once you have a CALayer, you can set any properties on it you'd like. But remember there's one property you definitely have to set: it's frame (or bounds/position).

What is CALayer in Swift?

An object that manages image-based content and allows you to perform animations on that content.

What is the layer property on a UIView object?

All UIView subclasses have a layer property, which is responsible for drawing their contents efficiently. These layers are powered by Core Animation, which handles all the drawing and animation that UIKit requests.

What is layer in view IOS?

A layer is a simple model class that exposes a number of properties to represents some image-based content. Every UIView is backed by a layer, so you can think of layers as the lower-level behind the scenes class behind your content.


1 Answers

The special-purpose CALayers like CAReplicatorLayer or CAGradientLayer are able (via private APIs) do execute their drawing directly on the GPU using fast filling or copying. In a sense they are different such that the backing store is not in normal RAM, but directly on the GPU.

like image 188
Cocoanetics Avatar answered Sep 20 '22 17:09

Cocoanetics