Some basic animation effects of a layer
#define Kradiantodegrees (Radian) (Radian * 180.0)/(M_PI)
[Self.testView.layer addanimation:[self opacityforever_animation:0.5] forkey:nil];
[Self.testView.layer addanimation:[self Duration:3 move:[nsnumber numberwithinteger:200]] forkey:nil];
[Self.testView.layer addanimation:[self scale:[nsnumber numberwithinteger:1] Orgin:[nsnumber Numberwithinteger:3] Durtimes:1 Rep:maxfloat] Forkey:nil];
Nsarray *myarray = [Nsarray arraywithobjects:[self opacityforever_animation:0.5], [self duration:1.0f move:[NSNumber NUMBERWITHFLOAT:200.0F]], [self scale:[nsnumber numberwithfloat:1.0f] Orgin:[nsnumber numberwithfloat:3.0f] DurTimes : 2.0f Rep:maxfloat], nil];
[Self.testView.layer addanimation:[self groupanimation:myarray durtimes:3.0f rep:maxfloat] forkey:nil];
Cgmutablepathref Mypah = cgpathcreatemutable ();
Cgpathmovetopoint (Mypah, nil,30, 77);
Cgpathaddcurvetopoint (Mypah, Nil, 50, 50, 60, 200, 200, 200);//Here is the control point.
[Self.testView.layer addanimation:[self keyframeanimation:mypah durtimes:5 rep:maxfloat] forkey:nil];
[Self.testView.layer addanimation:[self Rotation:2 degree:kradiantodegrees (All) Direction:1 Repeatcount:maxfloat] Forkey:nil];
[Self.testView.layer removeallanimations];
Implementation of the/******************************** method **************************************/
- #pragma mark = = Blink ======
1-(Cabasicanimation *) Opacityforever_animation: (float) Time2 3 {4 5Cabasicanimation *animation = [cabasicanimation animationwithkeypath:@"Opacity"];//must write opacity. 6 7Animation.fromvalue = [NSNumber numberwithfloat:1.0f];8 9Animation.tovalue = [NSNumber numberwithfloat:0.0f];//this is transparency. Ten OneAnimation.autoreverses =YES; A -Animation.duration =Time ; - theAnimation.repeatcount =maxfloat; - -Animation.removedoncompletion =NO; - +Animation.fillmode =kcafillmodeforwards; - +Animation.timingfunction=[camediatimingfunction Functionwithname:kcamediatimingfunctioneasein];///no words are evenly animated. A at returnanimation; - -}
- #pragma mark ===== Horizontal, vertical movement ===========
1-(Cabasicanimation *) Duration: (float) Time Move: (NSNumber *) x2 3 {4 5Cabasicanimation *animation = [cabasicanimation animationwithkeypath:@"transform.translation.x"];///. Y then move down. 6 7Animation.tovalue =x;8 9Animation.duration =Time ;Ten OneAnimation.removedoncompletion = NO;//Yes, and return to the original position. A -Animation.repeatcount =maxfloat; - theAnimation.fillmode =kcafillmodeforwards; - - returnanimation; - +}
- #pragma mark ===== Zoom-=============
1-(Cabasicanimation *) Scale: (NSNumber *) Multiple orgin: (NSNumber *) orginmultiple durtimes: (float) Time Rep: (float) Reperttimes2 3 {4 5Cabasicanimation *animation = [cabasicanimation animationwithkeypath:@"Transform.scale"];6 7Animation.fromvalue =multiple;8 9Animation.tovalue =orginmultiple;Ten OneAnimation.autoreverses =YES; A -Animation.repeatcount =Reperttimes; - theAnimation.duration = time;//when not set, there is a default zoom time. - -Animation.removedoncompletion =NO; - +Animation.fillmode =kcafillmodeforwards; - + returnanimation; A at}
- #pragma mark ===== Combo animation-=============
1-(Caanimationgroup *) Groupanimation: (Nsarray *) animationary durtimes: (float) Time Rep: (float) RepeatTimes2 3 {4 5Caanimationgroup *animation =[Caanimationgroup animation];6 7Animation.animations =animationary;8 9Animation.duration =Time ;Ten OneAnimation.removedoncompletion =NO; A -Animation.repeatcount =RepeatTimes; - theAnimation.fillmode =kcafillmodeforwards; - - returnanimation; - +}
- #pragma mark ===== Path animation-=============
1-(Cakeyframeanimation *) Keyframeanimation: (cgmutablepathref) path Durtimes: (float) Time Rep: (float) RepeatTimes2 3 {4 5Cakeyframeanimation *animation = [cakeyframeanimation animationwithkeypath:@"position"];6 7Animation.path =path;8 9Animation.removedoncompletion =NO;Ten OneAnimation.fillmode =kcafillmodeforwards; A -Animation.timingfunction =[Camediatimingfunction Functionwithname:kcamediatimingfunctioneasein]; - theAnimation.autoreverses =NO; - -Animation.duration =Time ; - +Animation.repeatcount =RepeatTimes; - + returnanimation; A at } - - #pragmaMark = = Rotation animation ====== --(Cabasicanimation *) Rotation: (float) Dur degree: (float) Degree direction: (int) Direction RepeatCount: (int) RepeatCount - - { in -Catransform3d rotationtransform = catransform3dmakerotation (degree,0,0, direction); to +Cabasicanimation *animation = [cabasicanimation animationwithkeypath:@"Transform"]; - theAnimation.tovalue =[Nsvalue Valuewithcatransform3d:rotationtransform]; * $Animation.duration =dur;Panax Notoginseng -Animation.autoreverses =NO; the +Animation.cumulative =NO; A theAnimation.fillmode =kcafillmodeforwards; + -Animation.repeatcount =RepeatCount; $ $Animation.Delegate=Self ; - - returnanimation; the -}
iOS development-Graphics and animation Chapter OC & Layers basically animated