1.CABasicAnimation Animation
Set global variable Picture
@property (Nonatomic,strong) Uiimageview *eyeimage;
Set the fillet (note: The light setting above a code is not implemented, the bottom of the Maskstobounds this property affects the shadow effect layer)
Self.eyeImage.layer.cornerRadius = 40;
Self.eyeImage.layer.masksToBounds = YES;
Set Shadow
Set the shadow color of a layer
Self.eyeImage.layer.shadowColor = [Uicolor yellow]. Cgcolor;
Set the layer transparency
Self.eyeImage.layer.shadowOpacity = 1.0;
Set the offset of the shadow
Self.eyeImage.layer.shadowOffSet = Cgsizemake ( -20,10);
Set the blur degree of a shadow
Self.eyeImage.layer.shadowRadius = 1.0f;
######### #自定义layer ######################
Create an Object
Calayer *layer = [Calayer layer];
Set the object's position and size
Layer.frame = CGRectMake (0,280,100,100);
Set Background color
Layer.backgroundcolor = [Uicolor Redcolor]. Cgcolor;
Layer needs to be added to layer
[Self.view.layer Addsublayer:layer];
Set anchor points
Layer.anchorpoint = Cgpointmake (0,0);
Set size (position)
Layer.position = Cgpointmake (100,100);
Cabasicanimation Animation
First step: Create an Animated object
Cabasicanimation *basicanimation = [cabasicanimation animation];
Step two: Tell the layer what you want to do with the animation [the content behind is set to the relevant properties of Calayer]
Basicanimation.keypath = @ "position";
Step three: Tell where to come from and where to go
Basicanimation.fromvalue = [Nsvalue valuewithcgpoint:cgpointmake (100,100)];
Basicanimation.tovalue = [Nsvalue valuewirhcgpoint:cgpointmake (300,300)];
Note: If you want to implement a moving position that does not return to the original position, you need to implement the following two lines of code
Basicanimation.removeoncompletion = NO;
Set content to save animation state
Basicanimation.fillmode = Kcafillmodeforwards;
Fourth Step: Set the duration of the animation
Basicanimation.duration = 6.0f;
Fifth step: Add the animations you want to perform to the Calayer layer
[Self.eyeImage.layer addanimation:basicanimation forkey:@ "Basic"];
############## #翻转效果 #######################
Cabasicanimation *basic = [cabasicanimation animation];
Basic.keypath = @ "transform";
Set the rollover to the place
Basic.tovalue = [Nsvalue valuewithcatransform3d:catransform3dmakerotation (m_pi_2,0,0,1)];
Basic.duration = 0.2f;
[Self.eyeImage.layer addanimation:basic forkey:@ "AAA"];
Remove animations based on key area
[Self.eyeImage.layer removeanimationforkey:@ "Basic"];
2.CAKeyFrameAnimation Animation
First step: Create an Object
Cakeyframeanimation *keyframeanimation = [cakeyframeanimation animation];
Step two: Set the animation track
Keyframeanimation.keypath = @ "Transform.rotation";
Step three: Set the rotation angle (radian calculation formula: Degrees/180*M_PI)
Keyframeanimation.values = @[@ ( -4/180.0 *m_pi), @ (4/180.0 *m_pi), @ (8/180 *m_pi)];
Fourth step: Set the length of time
Keyframeanimation.duration = 3.0f;
Fifth step: Add animations to layer layers
[Self.eyeImage.layer addanimation:keyframeanimation forkey:@ "Keyframeanimation"];
3.CAAnimationGroup Animation
Panning Animations
Cabasicanimation *basicanimation1 = [cabsicanimation animation];
Basicanimation1.keypath = @ "TRANSFORM.TRANSLATION.Y";
Basicanimation1.tovalue = @ (400);
Flip Animation
Cabasicanimation *basicanimation2 = [cabasicanimation animation];
Basicanimation2.keypath = @ "Transform.scale";
Basicanimation2.tovalue = @ (0.2);
Rotate animation
Cabasicanimation *baiscanimation3 = [cabasicanimation animation];
Basicanimation3.keypath = @ "Transform.rotation";
Basicanimation3.tovalue = @ (M_PI);
You need to create animation groups that manage individual animations
Caanimationgroup *group = [Caanimationgroup animation];
Group.animations = @[basicanimation1,basicanimation2,basicanimation3];
Group.duration = 5.0f;
[Self.eyeImage.layer addanimation:group forkey:@ "groupanimation"];
4.CASpringAnimation Animation
Caspringanimation *springanimation = [caspringanimation animation];
Springanimation.keypath = @ "Transform.scale";
Springanimation.fromvalue = @1;
Springanimation.tovalue = @0.25;
Springanimation.duration = 2.0f;
[Self.eyeImage.layer addanimation:springanimation forkey:@ "Springanimation"];
Ios-senior17-coreanimation Animation