Basic animation Cabasicanimation-Flash back to initial state after completion

Source: Internet
Author: User

Basic animation cabasicanimation After the end, the default flash back to the initial state, how to solve it?

Position requires two properties of the device:

1     // MARK:-Don't flash back after the end . 2     Anim.removedoncompletion = NO; 3     Anim.fillmode = Kcafillmodeforwards;

After setting, no more flash back, but the position of the control is not changed, but also in the original position, but the "display layer" moved to a new location.

You can do this by using the proxy method of the animation:

    // MARK:-Fix the position of the button by proxy method    ! // This agent is written in the NSObject category and does not require any protocol    . Anim.delegate = self;

To implement the Proxy method:

1 #pragmaMark-the Proxy method for core animations2 //Core Animation starts3- (void) Animationdidstart: (Caanimation *) Anim {4 5NSLog (@"Core Animation starts");6     7 }8 9 //end of core animationTen- (void) Animationdidstop: (Caanimation *) Anim finished: (BOOL) Flag { One      A //NSLog (@ "Core animation end!"); -     //at the end of the core animation, move the control's real position! -_btn.center = Cgpointmake ( Max, -); the      -     //Remove the animation from the layer to make sure it doesn't flash! - [_btn.layer removeallanimations]; -}

If it is transform.scale,transform.rotation, only need to set anim.removedoncompletion = NO;

Common Properties:

1Cabasicanimation *basicanimation = [cabasicanimation animationwithkeypath:@"POSITION.Y"];2 3Basicanimation.duration =2;4     5     //these three properties can only be set up to a maximum of 26Basicanimation.fromvalue = @ -;7Basicanimation.byvalue = @ -;8Basicanimation.tovalue = @ -;9     TenBasicanimation.repeatcount =Cgfloat_max; One      ABasicanimation.removedoncompletion =NO; -Basicanimation.fillmode =kcafillmodeforwards; -      the[_btn.layer addanimation:basicanimation Forkey:nil];

Basic animation Cabasicanimation-Flash back to initial state after completion

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.