Animations in iOS--core Animation

Source: Internet
Author: User

First, the basic animation cabasicanimation
1  //Initialization ModeCabasicanimation * cabase=[cabasicanimation animation];2  //set the properties that you want to animate through KeyPath, which is set to boundsCabase.keypath=@"bounds";3 //set the state of the animation at the end by TovalueCabase.tovalue=[nsvalue Valuewithcgrect:cgrectmake (0,0,Ten, -)]; //set the range of each change by ByvalueCabase.byvalue=[nsvalue Valuewithcgrect:cgrectmake (0,0,Ten, -)];//setting the state at the startCabase.fromvalue=[nsvalue Valuewithcgpoint:cgpointmake (0,0)];4  //set the duration of the animationcabase.duration=2; //Save AnimationCabase.fillmode=kcafillmodeforwards; //Save settings are not canceledcabase.removedoncompletion=NO; [_layer addanimation:cabase Forkey:nil];

case: Affine transformation animations through basic animations

 cabasicanimation * Cabase=[cabasicanimation Animation];cabase.keypath  =< Span style= "color: #800000;" >@ " transform  "  ;cabase.tovalue  =[nsvalue Valuewithcatransform3d:catransform3dmakescale (1 , 2 , 1  )];cabase.duration  =2  ;cabase.fillmode  =kcafillmodeforwards; Cabase.removedoncompletion  =no;[ _layer addanimation:cabase Forkey:nil];  
Second, key frame animation
1  //Initialization ModeCakeyframeanimation * keyfram=[cakeyframeanimation animation];2  //set the properties that you want to animate through KeyPath, which is set to positionKeyfram.keypath=@"position";3 //set the point at which the animation needs to passCgpoint p1=Cgpointzero; Cgpoint P2=cgpointmake ( Max,0); Cgpoint P3=cgpointmake ( Max, Max); Cgpoint P4=cgpointmake (0, Max); Cgpoint P5=Cgpointzero; Nsvalue* v1=[Nsvalue VALUEWITHCGPOINT:P1]; Nsvalue* v2=[Nsvalue VALUEWITHCGPOINT:P2]; Nsvalue* v3=[Nsvalue VALUEWITHCGPOINT:P3]; Nsvalue* v4=[Nsvalue VALUEWITHCGPOINT:P4]; Nsvalue* v5=[Nsvalue VALUEWITHCGPOINT:P5];4 //adds the corresponding value to the animation and sets the animation retentionkeyfram.values=@[v1,v2,v3,v4,v5]; Keyfram.duration=1; Keyfram.fillmode=kcafillmodeforwards; Keyfram.removedoncompletion=NO; [_layer Addanimation:keyfram Forkey:nil];

Case: Image rocking with keyframe animations

Cakeyframeanimation * anima=[cakeyframeanimation animation]; //by setting the angle of the radial transformationAnima.keypath=@"transform.rotation"; floatp1=4/180.0*M_pi; Anima.duration=0.2; Anima.values[Email protected] [@ (-P1), @ (p1), @ (-p1)]; Anima.fillmode=kcafillmodeforwards; Anima.removedoncompletion=NO; Anima.repeatcount=maxfloat; [_layer Addanimation:anima Forkey:nil];_layer.transform=catransform3dmakerotation (M_PI,0,0,0);
Third, transition animation
1  //Initialization ModeCatransition * tran=[catransition animation];2  //animating EffectsTran.type=@"Rippleeffect";//Common EffectsKcatransitionfadekcatransitionmoveinkcatransitionpushkcatransitionreveal3 //Set Animation directionTran.subtype=Kcatransitionfromleft;//Animation DirectionKcatransitionfromrightkcatransitionfromleftkcatransitionfromtopkcatransitionfrombottom4 //set animation retention and animation durationTran.fillmode=kcafillmodeforwards; Tran.removedoncompletion=NO; Tran.duration=1; [Self.myImageView.layer Addanimation:tran Forkey:nil];
Four, UIView package animation

Uikit integrates animations directly into the UIView class, and UIView provides animated support for these changes when some of the internal properties change. The work required to perform the animation is done automatically by the UIView class, but you still want to notify the view when you want to perform the animation, which requires that the code that changes the property be placed in the [UIViewbeginanimations: nil context : nil] and [UIView commitanimations]

1, common method analysis:

//set up an animation agent+ (void) Setanimationdelegate: (ID)Delegate   //sets the selector of the delegate object to be executed when the animation is about to begin, and passes the parameters passed in Beginanimations:context: into selector+(void) Setanimationwillstartselector: (SEL) Selector//To invoke a method at the end of a set animation+ (void) Setanimationdidstopselector: (SEL) Selector//set the duration of an animation+(void) Setanimationduration: (nstimeinterval) Duration//Set Animation delay+ (void) Setanimationdelay: (nstimeinterval) Delay//Set Animation start time+ (void) Setanimationstartdate: (NSDate *) StartDate//Set Animation Tempo+ (void) Setanimationcurve: (Uiviewanimationcurve) Curve//set the number of animations to repeat+ (void) Setanimationrepeatcount: (float) RepeatCount//If set to Yes, the effect of each repetition of the animation is the opposite of the previous one+(void) Setanimationrepeatautoreverses: (BOOL) repeatautoreverses//sets the transition effect of the view, transition specifies the transition type, and the cache setting yes represents the use of the view cache, better performance+ (void) Setanimationtransition: (uiviewanimationtransition) Transition Forview: (UIView *) View cache: (BOOL) cache

2. Case

   //Rotate Animation[UIView beginanimations:@"roate"Context:nil];    [UIView Setanimationcurve:uiviewanimationcurveeaseout]; [UIView setanimationduration:1.5];    [UIView setanimationdelegate:self]; _view.transform=cgaffinetransformrotate (_view.transform, m_pi_2); [UIView setanimationdidstopselector: @selector (endanimate)];    [UIView commitanimations]; //Transition Animations[UIView beginanimations:@"transition"Context:nil];    [UIView Setanimationcurve:uiviewanimationcurvelinear];    [UIView setanimationtransition:uiviewanimationtransitionflipfromright Forview:_mainview Cache:YES]; [UIView setanimationduration:1.5]; Nsinteger index1=[_mainview.subviews Indexofobject:_view]; Nsinteger Index2=[_mainview.subviews Indexofobject:_view2];    [_mainview exchangesubviewatindex:index1 Withsubviewatindex:index2]; [UIView commitanimations];

Animations in iOS--core Animation

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.