UIView Animation
Change the frame of UIView:
-(ibaction) Changeframe: (ID) Sender {//UIView Animation has the beginning BeginAnimation, has the end commitanimation//First step: start UIView animation[UIView beginanimations:@"Move"Context:nil]; //Step Two: Set the duration of the animation[UIView setanimationduration:3]; //Step Three: Set up the agent[UIView setanimationdelegate:self]; //Fourth Step: Set the frame of the related objectSelf.testView.frame = CGRectMake ( -, -, $, -); //Fifth Step: End animation[UIView commitanimations];}#pragmaMark-uiviewanimationdelegate's agent//Start Animation Method- (void) Animationwillstart: (NSString *) Animationid Context: (void*) context{NSLog (@"ID =%@,context =%@", Animationid,context);}//ways to end an animation- (void) Animationdidstop: (NSString *) Animationid finished: (NSNumber *) finished context: (void*) context{NSLog (@"ID =%@,context =%@", Animationid,context);}
Change the color of UIView
- (Ibaction) ChangeColor: (ID) Sender { [UIView beginanimations:@ "color" Context:nil]; [UIView setanimationduration: 2 ]; [UIView setanimationdelegate:self]; = [Uicolor redcolor]; [UIView commitanimations];}
Change the transparency of UIView
- (Ibaction) Changealpha: (ID) Sender { [UIView beginanimations:@ "Alpha" Context:nil]; [UIView setanimationduration: 5 ]; [UIView setanimationdelegate:self]; 0.2 ; [UIView commitanimations];}
UIView the Flip effect
-(ibaction) Rotaionaction: (ID) Sender {//Start Animation[UIView beginanimations:@"Rotation"Context:nil]; //set the length of time[UIView setanimationduration:1.5f]; //set the fade in effect[UIView setanimationcurve:uiviewanimationcurveeaseinout]; //Set up proxy[UIView setanimationdelegate:self]; //Set Rollover Direction[UIView setanimationtransition:uiviewanimationtransitioncurlup ForView:self.testView Cache:yes]; //End[UIView commitanimations]; }
UIView Rotation effect
//the effect of rotation-(ibaction) Transfromaction: (ID) Sender {[UIView beginanimations:@"Transfrom"Context:nil]; [UIView setanimationduration:3.0f]; [UIView setanimationdelegate:self]; [UIView Setanimationrepeatcount:-1]; //to rotate, set the angle of rotationCgaffinetransform Transfrom = cgaffinetransformmakerotation (3*M_PI); //object that sets the angle of rotation[Self.testview Settransform:transfrom]; [UIView commitanimations]; }
Coreanimation Animation
Some common properties of layer
//set the picture to rounded cornersSelf.imageview.layer.cornerRadius = self.imageview.frame.size.width/2;// //Note: Also set (Maskstobounds This property affects the shadow effect of the layer)//self.imageview.layer.masksToBounds = YES; //Set the shadow color of a layerSelf.imageview.layer.shadowColor =[Uicolor Redcolor]. Cgcolor; //Set TransparencySelf.imageview.layer.shadowOpacity =0.1; //set the offset of the shadowSelf.imageview.layer.shadowOffset = Cgsizemake ( -,Ten); //set the blur degree of a shadowSelf.imageview.layer.shadowRadius =1.0f; //requirements: Drag in UIView, set shadows,Self.uiView.layer.shadowColor=[Uicolor Orangecolor]. Cgcolor; Self.uiView.layer.shadowOpacity=0.5; Self.uiView.layer.shadowOffset= Cgsizemake ( -, -); Self.uiView.layer.shadowRadius=2.0f;
Custom Layer
- (void) customlayout{//Create a Layer objectCalayer *layer =[Calayer layer]; //set the position of an objectLayer.frame = CGRectMake (0,280, -, -); //Set Background colorLayer.backgroundcolor =[Uicolor Redcolor]. Cgcolor; //set anchor pointsLayer.anchorpoint = Cgpointmake (0,0); //set the size of the anchor point (position)Layer.position = Cgpointmake ( -, -); //Layer needs to be added to layer[Self.view.layer Addsublayer:layer]; }
Cabasicanimation Animation
-(ibaction) Basicanimation: (ID) Sender {//First step: Create an Animated objectCabasicanimation *basicanimation =[cabasicanimation animation]; //Step Two: Tell the layer what animations need to be performed, and what is set behind the Calay propertyBasicanimation.keypath =@"position"; //Step Three: Tell the layer where to go .Basicanimation.fromvalue = [Nsvalue valuewithcgpoint:cgpointmake ( -, -)]; Basicanimation.tovalue= [Nsvalue Valuewithcgpoint:cgpointmake ( -, -)]; //Note: If you want to implement a move to a location that does not return to the original location, you need to implement the following two lines;Basicanimation.removedoncompletion =NO; //set content to save animation stateBasicanimation.fillmode =kcafillmodeforwards; //fourth Step; set the duration of the animationBasicanimation.duration =3.0f; //Fifth Step: Add the animations you want to perform on Calayer[Self.imageview.layer addanimation:basicanimation Forkey:@"Basic"]; }
Cakeyframeanimation Animation
-(ibaction) Keyaction: (ID) Sender {//First step: Create an ObjectCakeyframeanimation *keyframeanimation =[cakeyframeanimation animation]; //Step Two: Set the animation trackKeyframeanimation.keypath =@"transform.rotation"; //Step Three: Set the rollover angle (calculation formula for radians: degrees/m_pi *)Keyframeanimation.values = @[@ ( -/180.0*M_PI), @ ( the/180.0*M_PI), @ ( the/180.0*M_pi)]; //fourth step; set the duration of the animationKeyframeanimation.duration =3.0f; //Fifth Step: Add the animation you want to perform to the layer[Self.imageview.layer addanimation:keyframeanimation Forkey:@"keyframeanimation"];}
Caanimationgroupaction Group Animation
-(ibaction) Caanimationgroupaction: (ID) Sender {//Panning AnimationsCabasicanimation *basicanimation1 =[cabasicanimation animation]; Basicanimation1.keypath=@"TRANSFORM.TRANSLATION.Y"; Basicanimation1.tovalue= @( -); //Flip AnimationCabasicanimation *basicanimation2 =[cabasicanimation animation]; Basicanimation2.keypath=@"Transform.scale"; Basicanimation2.tovalue= @(3);//radians//Rotate AnimationCabasicanimation *basicanimation3 =[cabasicanimation animation]; Basicanimation3.keypath=@"transform.rotation"; Basicanimation3.tovalue=@ (M_PI); //Create animation groups to manage animationsCaanimationgroup *group =[Caanimationgroup animation]; Group.animations=@[basicanimation1,basicanimation2,basicanimation3]; Group.duration=3.0f; [Self.imageview.layer addanimation:group Forkey:@"Group"]; }
- (Ibaction) Caspringaction: (ID) Sender { // Create object caspringanimation *spring = [ caspringanimation animation]; @" Transform.scale " ; = @1; = @0.25; 2.0f ; [Self.imageview.layer addanimation:spring Forkey: @" Spring " ];}
iOS Learning _ animation