I. cabasicanimation (basic animation)
Shift:
Cabasicanimation *animation =[cabasicanimation animation]; //keypath Specifies the animation category, position represents the shiftAnimation.keypath =@"position"; //move to X=200,y=200 's locationAnimation.tovalue = [Nsvalue valuewithcgpoint:cgpointmake ( $, $)]; Animation.duration=2; //Animations are not deleted after the animation is executedAnimation.removedoncompletion =NO; //keep up-to-date statusAnimation.fillmode =@"forwards"; //Add animations[Self.layer addanimation:animation Forkey:nil];
Scaling:
Cabasicanimation *animation =[cabasicanimation animation]; //keypath Specifies the animation category, bounds represents the zoomAnimation.keypath =@"bounds"; //Zoom to Width=50,height=50Animation.tovalue = [Nsvalue valuewithcgrect:cgrectmake (0,0, -, -)]; Animation.duration=2; //animation Complete does not delete animationAnimation.removedoncompletion =NO; //keep up-to-date statusAnimation.fillmode =@"forwards"; [Self.layer addanimation:animation Forkey:nil];
Rotating:
Cabasicanimation *animation =[cabasicanimation animation]; //keypath Specifies the animation category, transform represents the rotationAnimation.keypath =@"Transform"; //rotate clockwise 45 degrees along the x, Y axisAnimation.tovalue = [Nsvalue valuewithcatransform3d:catransform3dmakerotation (M_pi_4,1,1,0)]; Animation.duration=2; Animation.removedoncompletion=NO; Animation.fillmode=@"forwards"; [Self.layer addanimation:animation Forkey:nil];
Two. cakeyframeanimation (keyframe animation)
Cakeyframeanimation *anim =[cakeyframeanimation animation]; Anim.keypath=@"position"; Anim.removedoncompletion=NO; Anim.fillmode=kcafillmodeforwards; Anim.duration=2.0; //set a circular trajectory and move around a circular trajectoryCgmutablepathref Path =cgpathcreatemutable (); Cgpathaddellipseinrect (Path, NULL, CGRectMake ( -, -, $, $)); Anim.path=path; Cgpathrelease (path); //set the rhythm of an animation's execution//Kcamediatimingfunctioneaseineaseout: Slow at first, acceleration in the middle, slow at the endAnim.timingfunction =[Camediatimingfunction functionwithname:kcamediatimingfunctioneaseineaseout]; Anim.Delegate=Self ; [Anim setValue:@"AAA"Forkey:@"TAG"]; [Self.layer Addanimation:anim Forkey:nil];
Set the proxy callback method so that the animation pops up after the end of the prompt
- (void) Animationdidstop: (Caanimation *) Anim finished: (BOOL) flag{nsstring*strtag = [Anim valueforkey:@"TAG"]; if([Strtag isequaltostring:@"AAA"]) {Uialertview*alert = [[Uialertview alloc] Initwithtitle:@"Animation Done"Message@"Action Done" Delegate: Self Cancelbuttontitle:nil otherbuttontitles:@"Determine", nil]; [Alert show]; }}
Three. catransition (transition animation)
(1) View jump
_newview =[[UIView alloc] init]; _newview.frame= CGRectMake ( -, -, -, -); [Self.view Addsubview:_newview]; UIView*view1 =[[UIView alloc] init]; View1.frame= CGRectMake (0,0, -, -); View1.backgroundcolor=[Uicolor Yellowcolor]; [_newview Addsubview:view1]; UIView*view2 =[[UIView alloc] init]; View2.frame= CGRectMake (0,0, -, -); View2.backgroundcolor=[Uicolor Greencolor]; [_newview addsubview:view2];
Add Transition button Event handling:
-(ibaction) Exchangeview {//Transition AnimationsCatransition *transition =[catransition animation]; Transition.timingfunction=[Camediatimingfunction functionwithname:kcamediatimingfunctioneaseineaseout]; Transition.type=@"Pagecurl"; Transition.subtype=Kcatransitionfromright; Transition.duration=1; [_newview Exchangesubviewatindex:0Withsubviewatindex:1]; [_newview.layer addanimation:transition Forkey:@"myanimation"];}
(2) Controller jump
- (Ibaction) Pushview {catransition *transition = [catransition Animation]; Transition.timingfunction = [Camediatimingfunction functionwithname: Kcamediatimingfunctioneaseineaseout]; // stereoscopic animation effect Transition.type = @ " cube " @ " navanimation " *TESTVC = [[Testviewcontroller alloc] init]; [Self.navigationcontroller SHOWVIEWCONTROLLER:TESTVC sender:nil];}
Four. Caanimationgroup (Combo animation)
//Add a pictureUiimageview *imgview = [[Uiimageview alloc] initwithimage:[uiimage imagenamed:@"curry.jpg"]]; Imgview.frame= CGRectMake ( -, -, ImgView.frame.size.width, imgView.frame.size.height); [Self.view Addsubview:imgview]; //Bézier curve PathUibezierpath *movepath =[Uibezierpath Bezierpath]; [Movepath Movetopoint:cgpointmake (10.0,10.0)]; [Movepath Addquadcurvetopoint:cgpointmake ( -, -) Controlpoint:cgpointmake ( -, -)]; //The following must import the Quartzcore package//keyframe Animation (position)Cakeyframeanimation * Posanim = [cakeyframeanimation animationwithkeypath:@"position"]; Posanim.path=Movepath.cgpath; Posanim.removedoncompletion=YES; //Zoom AnimationCabasicanimation *scaleanim = [cabasicanimation animationwithkeypath:@"Transform"]; Scaleanim.fromvalue=[Nsvalue valuewithcatransform3d:catransform3didentity]; Scaleanim.tovalue= [Nsvalue Valuewithcatransform3d:catransform3dmakescale (0.1,0.1,1.0)]; Scaleanim.removedoncompletion=YES; //Transparent animationsCabasicanimation *opacityanim = [cabasicanimation animationwithkeypath:@"Alpha"]; Opacityanim.fromvalue= [NSNumber numberwithfloat:1.0]; Opacityanim.tovalue= [NSNumber numberwithfloat:0.1]; Opacityanim.removedoncompletion=YES; //Animation GroupCaanimationgroup *animgroup =[Caanimationgroup animation]; Animgroup.animations=[Nsarray Arraywithobjects:posanim, Scaleanim, Opacityanim, nil]; Animgroup.duration=1; [Imgview.layer Addanimation:animgroup Forkey:nil];
IOS Core Animation Learning Summary (3)--basic types of animations