Animation group Caanimationgroup is very simple to use, the core idea is to combine multiple animation effects, each animation effect parallel processing, these animation effects can be cabasicanimation, or it can be cakeyframeanimation
- (void) viewdidload{[Super Viewdidload]; Calayer*layer =[Calayer layer]; Layer.bounds= CGRectMake (0,0, -, -); Layer.position= Cgpointmake ( -, -); Layer.cornerradius= -; Layer.maskstobounds=YES; Layer.contents= (ID) [UIImage imagenamed:@"5.png"]. Cgimage; [Self.view.layer Addsublayer:layer];}- (void) touchesended: (Nsset *) touches withevent: (Uievent *)Event{Calayer*layer =[Self.view.layer.sublayers Lastobject]; //Rotation AnimationCabasicanimation *animation = [cabasicanimation animationwithkeypath:@"transform.rotation.z"]; Animation.tovalue=@M_PI; Animation.autoreverses=YES; Animation.duration=1; //rotate an animation around a matrixCakeyframeanimation *keyframeanimation = [cakeyframeanimation animationwithkeypath:@"position"]; Cgpathref Path=cgpathcreatemutable (); Cgpathaddrect (Path,&cgaffinetransformidentity, CGRectMake (layer.position.x, LAYER.POSITION.Y, $, -)); Keyframeanimation.path=path; Keyframeanimation.duration=2; Cgpathrelease (path); //Create an animation group that contains the previous two animationsCaanimationgroup *animationgroup =[Caanimationgroup animation]; Animationgroup.animations=@[animation,keyframeanimation]; Animationgroup.duration=2; Animationgroup.repeatcount=huge_valf; [Layer Addanimation:animationgroup Forkey:nil]; }
The effect of the above code is that the picture rotates around the rectangular path in the edge
iOS animation (4) Animation group