Cakeyframeanimation Common properties and how to shake view

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.