iOS development-Graphics and animation Chapter OC & Layers basically animated

Source: Internet
Author: User

Some basic animation effects of a layer

#define Kradiantodegrees (Radian) (Radian * 180.0)/(M_PI)

    • Flashing

[Self.testView.layer addanimation:[self opacityforever_animation:0.5] forkey:nil];

    • Mobile

[Self.testView.layer addanimation:[self Duration:3 move:[nsnumber numberwithinteger:200]] forkey:nil];

    • Zoom

[Self.testView.layer addanimation:[self scale:[nsnumber numberwithinteger:1] Orgin:[nsnumber Numberwithinteger:3] Durtimes:1 Rep:maxfloat] Forkey:nil];

    • Combination

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];

    • Path

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];

    • Rotation

[Self.testView.layer addanimation:[self Rotation:2 degree:kradiantodegrees (All) Direction:1 Repeatcount:maxfloat] Forkey:nil];

    • Removed from

[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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.