| First, the basic animation cabasicanimation |
1 //Initialize mode cabasicanimation * cabase=[cabasicanimation animation];2 //The properties that need to be animated are set by KeyPath, this is set to bounds[ Email protected] "bounds"; 3//Set the state Cabase.tovalue=[nsvalue valuewithcgrect:cgrectmake (0, 0, 10, 100) at the end of the animation by Tovalue; Set the range of each change by Byvalue Cabase.byvalue=[nsvalue valuewithcgrect:cgrectmake (0, 0, 10, 100)];//setting the state at the start Cabase.fromvalue=[nsvalue valuewithcgpoint:cgpointmake (0, 0)];4 //Set animation duration cabase.duration=2; Save animation Cabase.fillmode=kcafillmodeforwards; Save settings do not cancel cabase.removedoncompletion=no;[ _layer Addanimation:cabase Forkey:nil];
case: Affine transformation animations through basic animations
Cabasicanimation * Cabase=[cabasicanimation animation]; [Email protected] "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 //Initialize mode cakeyframeanimation * keyfram=[cakeyframeanimation animation];2 //The properties that need to be animated are set by KeyPath This is set to Position[email protected] "position"; 3//Set animation need to pass the point cgpoint P1=cgpointzero; Cgpoint p2=cgpointmake (0); Cgpoint P3=cgpointmake (a); Cgpoint p4=cgpointmake (0,); 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//Add the corresponding value to the animation and set the animation retention [email protected][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 radiation transformation to achieve [email protected] "transform.rotation"; float P1=4/180.0*m_pi; anima.duration=0.2; [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);
| III, transition animation |
1//Initialize mode catransition * tran=[catransition animation];2//Animate effect [email Protected] "rippleeffect";//Common effect KCATRANSITIONFADEKCATRANSITIONMOVEINKCATRANSITIONPUSHKCATRANSITIONREVEAL3// Set Animation direction tran.subtype=kcatransitionfromleft;// Animation direction KCATRANSITIONFROMRIGHTKCATRANSITIONFROMLEFTKCATRANSITIONFROMTOPKCATRANSITIONFROMBOTTOM4//Set animation retention and animation duration Tran.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 parsing:
//set animation agent + (void) Setanimationdelegate: (ID) delegate//set when the animation is about to start, Executes the selector of the delegate object and passes the parameters passed in Beginanimations:context: selector + (void) Setanimationwillstartselector: (SEL) Selector//Set animation End call Method + (void) Setanimationdidstopselector: (SEL) selector//Set animation duration + (void) Setanimationduration: ( Nstimeinterval) duration//Set animation delay + (void) Setanimationdelay: (nstimeinterval) delay//Set Animation start time + (void) Setanimationstartdate: (NSDate *) startdate//Set animation rhythm + (void) Setanimationcurve: (Uiviewanimationcurve) curve//Set animation repeat Count + (void) Setanimationrepeatcount: (float) repeatcount//If set to Yes, the effect of each repetition of the animation is followed by the opposite + (void) Setanimationrepeatautoreverses: (BOOL) repeatautoreverses//Set the transition effect for view views, transition Specify the transition type, and the cache setting yes means using the view cache. Good performance + (void) Setanimationtransition: (uiviewanimationtransition) Transition Forview: (UIView *) View cache: (BOOL) cache
2. Case
Rotation 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 animation [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