Order
The Careplicatorlayer can copy layers of its own child layer, and the copied layer has the same dynamic effect as the original child. Then by setting some properties, you can do cool results, very powerful.
Effect
Love_music.gifdemo
It is recommended to download the demo first, combined with the following analysis, will be good to understand the point. Address Https://github.com/Resory/RYReplicatorLayer
Logic
- This paper mainly deals with the making of the dynamic effect of love. Music action can be referenced by the Love action note.
- First we need to get a love path, this path is made with Uibezierpath.
- Then generate a uiview, its layer plus cakeyframeanimation, and Cakeyframeanimation's path is the love path.
- Add the UIView layer to the Careplicatorlayer. and set Careplicatorlayer the corresponding properties.
Realize
- Love path
Uibezierpath *tpath = [Uibezierpath Bezierpath]; [Tpath movetopoint:cgpointmake (Sys_device_width/2.0 , )]; [Tpath addquadcurvetopoint:cgpointmake (Sys_device_width/2.0 , 400 ) controlpoint:cgpointmake (Sys_device_width/2.0 + 200 , 20 )]; [Tpath addquadcurvetopoint:cgpointmake (Sys_device_width/2.0 , 200 ) controlpoint:cgpointmake (Sys_device_width/2.0 -200 , 20 )]; [Tpath Closepath];
- The
- generates a uiview
UIView *tview = [[UIView alloc] Initwithframe:cgrectmake ( Span class= "Hljs-number" >0 , 0 , 10 , 10 )]; Tview.center = Cgpointmake (Sys_device_width/2.0 , 200 ); TView.layer.cornerRadius = 5 ; Tview.backgroundcolor = [Uicolor colorwithred:1.0 Green: 1.0 blue:1.0 alpha: 1.0 ];
- Add Cakeyframeanimation action to the UIView
CAKeyframeAnimation *loveAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; loveAnimation.path = tPath.CGPath; loveAnimation.duration8; loveAnimation.repeatCount = MAXFLOAT; [tView.layer addAnimation:loveAnimation forKey:@"loveAnimation"];
- Generate a Careplicatorlayer and add the UIView layer to it
_lovelayer = [Careplicatorlayer layer]; _lovelayer.instancecount = 40 ; //copy 39 sub-layer+ the original child layer Total 40 layer _lovelayer.instancedelay = 0.2 ; //every 0.2 appears a layer _lovelayer.instancecolor = [Uicolor colorwithred:1.0 green:1.0 blue:1.0 Alpha:1.0 ]. Cgcolor; _lovelayer.instancegreenoffset =-0.03 ; //color values are decremented. _lovelayer.instanceredoffset =-0.02 ; //color values are decremented. _lovelayer.instanceblueoffset =-0.01 ; //color values are decremented.
- [_lovelayer AddSublayer:tView.layer];
[Self.view.layer Addsublayer:_lovelayer];
Late
-
Careplicatorlayer also has a instancetransform attribute, Musiclayer is done with its Instancetransform property. So there are a lot of effects that can be done. Just look at your brain hole is not big enough.
-
If you have a question or if you find an error, please leave a message for me. 3q~~
- Fill a picture, otherwise the article has no picture.
Create path
Uibezierpath *p11 = [Uibezierpath Bezierpath];
[P11 setlinewidth:2.0];
[P11 moveToPoint: (Cgpointmake (100, 200)];
[P11 Addlinetopoint: (Cgpointmake (150, 200)];
[P11 Addlinetopoint: (Cgpointmake (175, 150))];/ /zhong
P11.linecapstyle = Kcglinecapsquare;
P11.linejoinstyle = Kcglinejoinmiter;
[P11 Addlinetopoint: (Cgpointmake (200, 200)];
[P11 Addlinetopoint: (Cgpointmake (250, 200)];
[P11 Addlinetopoint: (Cgpointmake (210, 230)];
[P11 Addlinetopoint: (Cgpointmake (235, 275)];
[P11 Addlinetopoint: (Cgpointmake (175, 250))];/ /
[P11 Addlinetopoint: (Cgpointmake (115, 275)];
[P11 Addlinetopoint: (Cgpointmake (140, 230)];
[P11 Closepath];
Calayer *tview = [[Calayer alloc] init];
Tview.frame = CGRectMake (0, 0, 10, 10);
Tview.position = Cgpointmake (SELF.VIEW.FRAME.SIZE.WIDTH/2, 400);
Tview.cornerradius = 5;
Tview.backgroundcolor = [Uicolor Whitecolor]. Cgcolor;
Tview.opacity = 0.1;
Mobile animation
Cakeyframeanimation *loveanimation = [cakeyframeanimation animationwithkeypath:@ "position"];
Loveanimation.path = P11. Cgpath;
Loveanimation.duration = 10;
Loveanimation.repeatcount = maxfloat;
Zoom Animation
Cabasicanimation *scaleanimation = [cabasicanimation animationwithkeypath:@ "transform"];
Scaleanimation.fromvalue = [Nsvalue valuewithcatransform3d:catransform3didentity];
Scaleanimation.tovalue = [Nsvalue valuewithcatransform3d: (Catransform3dmakescale (0.15, 0.15, 1.0)];
Scaleanimation.duration = 1;
Scaleanimation.repeatcount = maxfloat;
Transparency Animation
Cabasicanimation *opacityanimation = [cabasicanimation animationwithkeypath:@ "opacity"];
Opacityanimation.duration = 10;
Opacityanimation.tovalue = @ (1.0);
Opacityanimation.fillmode = Kcafillmodeforwards;
Group Animations
Caanimationgroup *group = [Caanimationgroup animation];
Group.animations = @[loveanimation,scaleanimation,opacityanimation];
Group.duration = 10;
Group.repeatcount = maxfloat;
[TView Addanimation:group Forkey:nil];
Careplicatorlayer *lovelayer = [Careplicatorlayer layer];
Lovelayer.instancecount = 40;
Lovelayer.instancedelay = 0.2;
Lovelayer.instancecolor = [Uicolor Greencolor]. Cgcolor;
Lovelayer.instancegreenoffset =-0.01;
Lovelayer.instanceredoffset =-0.01;
Lovelayer.instanceblueoffset =-0.01;
[Lovelayer Addsublayer:tview];
[Self.view.layer Addsublayer:lovelayer];
Music animation
_musiclayer = [Careplicatorlayer layer];
_musiclayer.frame = CGRectMake (0, 0, 60, 80);
_musiclayer.position = Self.view.center;
_musiclayer.instancecount = 3;
_musiclayer.instancetransform = catransform3dmaketranslation (20, 0, 0); The spacing for each layer.
_musiclayer.instancedelay = 0.2;
_musiclayer.backgroundcolor = [Uicolor Whitecolor]. Cgcolor;
_musiclayer.maskstobounds = YES;
[Self.view.layer Addsublayer:_musiclayer];
Calayer *tlayer = [Calayer layer];
Tlayer.frame = CGRectMake (10, 100, 10, 30);
Tlayer.backgroundcolor = [Uicolor Redcolor]. Cgcolor;
[_musiclayer Addsublayer:tlayer];
Cabasicanimation *musicanimation = [cabasicanimation animationwithkeypath:@ "POSITION.Y"];
Musicanimation.duration = 0.35;
Musicanimation.fromvalue = @ (100);
Musicanimation.tovalue = @ (75);
musicanimation.autoreverses = YES;
Musicanimation.repeatcount = maxfloat;
[Tlayer addanimation:musicanimation forkey:@ "Musicanimation"];
IOS Quartzcore The sixth chapter--careplicatorlayer application