CAReplicatorLayer的目的是为了高效生成许多相似的图层。它会绘制一个或多个图层的子图层,并在每个复制体上应用不同的变换。

一、简介

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#import <QuartzCore/CALayer.h>
NS_ASSUME_NONNULL_BEGIN
/* The replicator layer creates a specified number of copies of its
* sublayers, each copy potentially having geometric, temporal and
* color transformations applied to it.
*
* Note: the CALayer -hitTest: method currently only tests the first
* instance of z replicator layer's sublayers. This may change in the
* future. */
CA_CLASS_AVAILABLE (10.6, 3.0, 9.0, 2.0)
@interface CAReplicatorLayer : CALayer
/* The number of copies to create, including the source object.
* Default value is one (i.e. no extra copies). Animatable. */
@property NSInteger instanceCount;
/* Defines whether this layer flattens its sublayers into its plane or
* not (i.e. whether it's treated similarly to a transform layer or
* not). Defaults to NO. If YES, the standard restrictions apply (see
* CATransformLayer.h). */
@property BOOL preservesDepth;
/* The temporal delay between replicated copies. Defaults to zero.
* Animatable. */
@property CFTimeInterval instanceDelay;
/* The matrix applied to instance k-1 to produce instance k. The matrix
* is applied relative to the center of the replicator layer, i.e. the
* superlayer of each replicated sublayer. Defaults to the identity
* matrix. Animatable. */
@property CATransform3D instanceTransform;
/* The color to multiply the first object by (the source object). Defaults
* to opaque white. Animatable. */
@property(nullable) CGColorRef instanceColor;
/* The color components added to the color of instance k-1 to produce
* the modulation color of instance k. Defaults to the clear color (no
* change). Animatable. */
@property float instanceRedOffset;
@property float instanceGreenOffset;
@property float instanceBlueOffset;
@property float instanceAlphaOffset;
@end
NS_ASSUME_NONNULL_END
  • instanceCount:重复图层数量;
  • instanceDelay:延迟时间,默认:0;
  • instanceTransform:变换;
  • instanceColor:颜色;
  • instanceRedOffset:Red 偏移;
  • instanceGreenOffset:Green 偏移;
  • instanceBlueOffset:Blue 偏移;
  • instanceAlphaOffset:Alpha 偏移;

二、动画效果