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