1 //Create a Frame animation object (zoom bounds, pan position, rotate transform)2Cakeyframeanimation *anim = [cakeyframeanimation animationwithkeypath:@"position"];3 //values are used to store every frame of animation to be performed4Nsvalue *value1 =[Nsvalue Valuewithcgpoint:cgpointzero];5Nsvalue *value2 = [Nsvalue valuewithcgpoint:cgpointmake ( -,0)];6Nsvalue *value3 = [Nsvalue valuewithcgpoint:cgpointmake ( -, -)];7Nsvalue *value4 = [Nsvalue valuewithcgpoint:cgpointmake (0, -)];8Nsvalue *value5 =[Nsvalue Valuewithcgpoint:cgpointzero];9Anim.values =@[value1,value2,value3,value4,value5];Ten One //set the time for each frame execution (note: Each value in the value range is 0 to 1, and the following value must be greater than the previous value) A //time of execution per frame = (last point in time-previous point in time) * Total time of animation execution -Anim.keytimes = @[@ (0),@(0.2),@(0.5),@(0.7),@(1)]; - the //Set animation execution Rhythm (slow-forward full-out, middle-fast) - //anim.timingfunction = [camediatimingfunction functionwithname:kcamediatimingfunctioneaseineaseout]; - //Set Animation time -Anim.duration =2.0f; + - //set Save animation execution State +Anim.removedoncompletion =NO; AAnim.fillmode =kcafillmodeforwards; at //add animations to layers -[Self.redView.layer Addanimation:anim Forkey:nil];
Jitter Picture
Convert Angle to radians
#define Angleradian (angle) ((angle) * m_pi/ 180.0)
1 if([Self.iconView.layer Animationforkey:@"Animation"]){//If the animation is in progress2 //Stop Animation3[Self.iconView.layer Removeanimationforkey:@"Animation"];4 return;5 }6 //Create an animated object7Cakeyframeanimation *keyframe = [cakeyframeanimation animationwithkeypath:@"transform.rotation.z"];8 9Keyframe.values = @[@ (-angleradian (3), @ (Angleradian (3), @ (-angleradian (3))];Ten One //Set up proxy AKeyframe.Delegate=Self ; - - //Set Animation time theKeyframe.duration =0.2f; - //set animation execution times -Keyframe.repeatcount =maxfloat; - + //add animations to your avatar -[Self.iconView.layer addanimation:keyframe Forkey:@"Animation"];
#pragma mark- animation Agent Method
-(void) Animationdidstart: (caanimation *) anim {
NSLog(@ "Animationdidstart");
}
-(void) Animationdidstop: (caanimation *) Anim finished: (BOOL) flag {
NSLog(@ "Animationdidstop");
}
Cakeyframeanimation Common properties and how to shake view