Careplicatorlayer:
The main functions are the following two:
- The purpose of Careplicatorlayer is to efficiently generate many similar layers, which draw sublayers of one or more layers and apply different transformations on each replicator
- Use one of the practical applications of Careplicatorlayer: Reflection uses Careplicatorlayer and applies a negative scale transform to a duplicate layer you can create a mirrored picture of the content of the specified view so that you create a real-time reflection effect
First look at the first code example:
/*Create a template layer Careplicatorlayer will "clone" the template according to certain rules*/Cashapelayer*shape =[Cashapelayer layer]; Shape.frame= CGRectMake (0,0, the, the); /*drawing the shape of a template*/Shape.path= [Uibezierpath Bezierpathwithovalinrect:cgrectmake (0,0, the, the)]. Cgpath; /*fill Color of the template*/Shape.fillcolor=[Uicolor Redcolor]. Cgcolor; Shape.opacity=0.0; /*Create an animation group (or a single animation) of all child layers*/Caanimationgroup*animationgroup =[Caanimationgroup animation]; /*Animation Group Elements*/animationgroup.animations=@[[self alphaanimation],[self Scaleanimation]]; /*Animation Execution Time*/animationgroup.duration=4.0; Animationgroup.autoreverses=NO; Animationgroup.repeatcount=HUGE; /*adding animations to the template layer essentially adds animations to each Careplicatorlayer child layer*/[Shape addanimation:animationgroup forkey:@"Animationgroup"]; /*Create a Careplicatorlayer object*/Careplicatorlayer*replicatorlayer =[Careplicatorlayer layer]; Replicatorlayer.frame=Self.containerView.bounds; /*set the time interval for each element to be added*/Replicatorlayer.instancedelay=0.5; /*set the number of elements per element*/Replicatorlayer.instancecount=8;
/* Add a transform rule to the child layer of the Careplicatorlayer object here determines the layout of the child layer */
Replicatorlayery.instancetransform = catransform3dtranslate (catransform3didentity, 0, Radius+between, 0);
/* Add a sub -layer * /
[Replicatorlayer Addsublayer:shape];
Here, you can add different animation elements as needed or do not add any animations, which are used to animate the load prompt view.
A second usage that implements the reflection effect of a view:
We first inherit UIView to create a subclass that sets the layer of the current view object to the Careplicatorlayer object in the subclass's + (Class) Layerclass method:
+(Class) layerclass{ returnclass];}
Then set the relevant parameters for the Self.layer when you create the object for the subclass:
- (void) setup{/*Gets the current layer is actually a Careplicatorlayer object*/Careplicatorlayer*layer = (Careplicatorlayer *) Self.layer; Layer.instancecount=2; Layer.anchorpoint= Cgpointmake (0.5,0.5); /*Create 3D conversion effects*/Catransform3d Transform=catransform3didentity; CGFloat Verticaloffset=Self.bounds.size.height; Transform= Catransform3dtranslate (Transform,0, Verticaloffset,0); /*Set Y-axis specular reflection*/Transform= Catransform3dscale (Transform,1, -1,0); Transform= Catransform3drotate (transform,-M_PI/4,1,0,0); Layer.instancetransform=transform; /*the lower the transparency of the mirror, the clearer it is because the mirror effect*/Layer.instancealphaoffset= -0.1;}
As follows
The Careplicatorlayer of Coreanimation