First, UIView animation
UIView Animation has the beginning BeginAnimation, has the end commitanimation
First step: Start UIView animation
[UIView beginanimations:@ " identification ID (can be arbitrarily named)" Context:nil ";
Step two: Set the animation duration
[UIView Setanimationduration:3];
Step three: Set the callback proxy for the UIView animation
[UIView setanimationdelegate:self];
Fourth step: Set the frame of the related object (or Color,alpha properties)
_testview.frame = CGRectMake (100, 100, 200, 100);
_testview.backgroundcolor = [Uicolor Redcolor];
_testview.alpha = 0.2;
Fifth Step: End animation (submit animation effect)
[UIView commitanimations];
The third step satisfies the callback protocol after the Protocol method:
How to start an animation
-(void) Animationwillstart: (NSString *) Animationid context: (void *) Context {
NSLog (@ "ID =%@,context =%@", Animationid, context);
}
How to end an animation
-(void) Animationdidstop: (NSString *) Animationid finished: (NSNumber *) finished context: (void *) Context {
NSLog (@ "ID =%@,context =%@", Animationid, context);
}
Second, coreanimation animation
Properties of 1.layer
#pragma Mark-layer Common Properties /* //Set the picture to fillet Self.imageView.layer.cornerRadius = SELF.IMAGEVIEW.FRAME.SIZE.WIDTH/2; Note: The light setting above a code is not effective (maskstobounds This property affects the shadow effect of the layer, causing the shadow not to show)//Allow to change the angle//self.imageview.layer.maskstobounds = YES ; Sets the shadow color of the layer Self.imageView.layer.shadowColor = [Uicolor Redcolor]. Cgcolor; Set the layer transparency self.imageView.layer.shadowOpacity = 0.5f; Sets the offset of the shadow Self.imageView.layer.shadowOffset = Cgsizemake (-20, 10); Sets the blur degree of the shadow Self.imageView.layer.shadowRadius = 1.0f; Requirement: Drag in a uiview to set its shadow Self.myView.layer.shadowColor = [Uicolor blackcolor]. Cgcolor; self.myView.layer.shadowOpacity = 1; Self.myView.layer.shadowOffset = Cgsizemake (20, 0); Self.imageView.layer.shadowRadius = 3; */
Layer Common Properties
2. Various animation implementation method steps
- Declaring method names
- KeyPath assigned to the corresponding animation operation
- Set the property values required for an animation operation
- Add the animation action to the layer of the picture
#pragmaMark-caspringanimation Animation button Response Method-(Ibaction) Springanimation: (ID) Sender {caspringanimation*springanimation =[caspringanimation animation]; Springanimation.keypath=@"Transform.scale"; Springanimation.fromvalue= @1; Springanimation.tovalue= @0.25; Springanimation.duration=3.0f; [Self.imageView.layer addanimation:springanimation Forkey:@"springanimation"]; }#pragmaMark-caanimationgroup Group Animation button Response Method-(Ibaction) Animationgroup: (ID) Sender {//Panning AnimationsCabasicanimation *basicanimation1 =[cabasicanimation animation]; Basicanimation1.keypath=@"TRANSFORM.TRANSLATION.Y"; Basicanimation1.tovalue= @( -); //Shrink AnimationCabasicanimation *basicanimation2 =[cabasicanimation animation]; Basicanimation2.keypath=@"Transform.scale"; Basicanimation2.tovalue= @(0.2); //Rotate AnimationCabasicanimation *basicanimation3 =[cabasicanimation animation]; Basicanimation3.keypath=@"transform.rotation"; Basicanimation3.tovalue=@ (M_PI); //you need to create animation groups that manage individual animationsCaanimationgroup *group =[Caanimationgroup animation]; Group.animations=@[basicanimation1, BasicAnimation2, BasicAnimation3]; Group.duration=5.0f; [Self.imageView.layer addanimation:group Forkey:@"groupanimation"]; }#pragmaMark-cakeyframeanimation Animation button Response Method-(Ibaction) Keyframeanimation: (ID) Sender {//First step: Create an ObjectCakeyframeanimation *keyframeanimation =[cakeyframeanimation animation]; //Step Two: Set the animation trackKeyframeanimation.keypath =@"transform.rotation"; //Step Three: Set the rotation angle (calculation formula for radians: degrees/180*π) (π= m_pi)Keyframeanimation.values = @[@ (0/180.0* m_pi), @ ( the/180.0*M_pi)]; Keyframeanimation.repeatcount=3; //Fourth Step: Set the length of timeKeyframeanimation.duration =3.0f; //Fifth Step: Add animations to layer layers[Self.imageView.layer addanimation:keyframeanimation Forkey:@"keyframeanimation"]; }#pragmaMark-cabasicanimation Animation Response Method-(Ibaction) Basicanimation: (ID) Sender {/*************** Move effect ***************/ //First step: Create an Animated objectCabasicanimation *basicanimation =[cabasicanimation animation]; //Step Two: Tell the layer what you need to do to animate [the content that is set later is Calayer's related property]Basicanimation.keypath =@"position"; //Step Three: Tell the layer where to come from and where to goBasicanimation.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 its original location, you need to implement the following two lines of codeBasicanimation.removedoncompletion =NO; //set content to save animation stateBasicanimation.fillmode =kcafillmodeforwards; //Fourth Step: Set the duration of the animationBasicanimation.duration =4; //Fifth Step: Add the animations you want to perform on Calayer[Self.imageView.layer addanimation:basicanimation Forkey:@"Basic1"]; /*************** Rollover effect ***************/cabasicanimation*basic =[cabasicanimation animation]; Basic.keypath=@"Transform"; //set the rollover to the placeBasic.tovalue = [Nsvalue valuewithcatransform3d:catransform3dmakerotation (M_PI,0,0,1)]; Basic.duration=2.0f; [Self.imageView.layer addanimation:basic Forkey:@"Basic2"]; //Remove animation based on key removal//[Self.imageView.layer removeanimationforkey:@ "Basic1"]; }
Several ways to implement iOS advanced animation