A layer that creates a specified number of sublayer copies with varying geometric, temporal, and color transformations.
- iOS 3.0+
- macOS 10.6+
- Mac Catalyst 13.0+Beta
- tvOS 9.0+
- Core Animation
You can use a
CAReplicator object to build complex layouts based on a single source layer that is replicated with transformation rules that can affect the position, rotation color, and time.
The code in Listing 1 shows a simple example: a red square is added to a replicator layer with an instance count of
5. The position of each replicated instance is offset along the
x axis so that it appears to the right of the previous instance. The blue and green color channels are offset so that their values reach
0 at the final instance.
The result of the code above is a row of five squares, with colors graduating from white to red, as shown in Figure 1.
Replicator layers can be nested. The code in Listing 2 adds
replicator to a second replicator layer that offsets the position of each instance vertically and subtracts from the red channel.