
弹出:
CAKeyframeAnimation *animation = [CAKeyframeAnimationanimationWithKeyPath:@"transform.scale"];
animation.values =@[@(0.01),@(1.2),@(0.9),@(1)];
animation.keyTimes = @[@(0),@(0.4),@(0.6),@(1)];
animation.timingFunctions =@[[CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionLinear],
[CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionLinear], [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseOut]];
animation.duration = 0.5;
animation.delegate = self;
[popImageView1.layer addAnimation:animationforKey:@"bouce"];
点击消失:
CAKeyframeAnimation *animation = [CAKeyframeAnimationanimationWithKeyPath:@"transform.scale"];
animation.values = @[@(1),@(1.2),@(0.01)];
animation.keyTimes = @[@(0),@(0.4),@(1)];
animation.timingFunctions =@[[CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut],
[CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseOut]];
animation.duration = 0.35;
animation.delegate = self;
[button.superview.layeraddAnimation:animationforKey:@"bounce"];
button.superview.transform =CGAffineTransformMakeScale(0.001,0.001);
若要区分动画,则可以这样 (已测 可以达到效果chenyong) 20140122 (这样貌似也有点问题,偶尔会崩溃好像,可以设置一个全局int值 ,来区分动画)
[animation setValue:@"throbUp" forKey:@"animationID"];
|
All other answers are either too complicated or requires instance variables for each animations.
This solution is very easy all you need is to add your own key to the animation (animationID in this example) it does
not require any instance variables:
Insert this line to identify volumeControlFadeToOrange:
[volumeControlAnimation setValue:@"volumeControlFadeToOrange" forKey:@"animationID"];
and this to identify throbUp animation:
[animation setValue:@"throbUp" forKey:@"animationID"];
Test it like this:
- (void)animationDidStop:(CAAnimation *)animation finished:(BOOL)flag
{
if([[animation valueForKey:@"animationID"] isEqual:@"volumeControlFadeToOrange"]) {
//animation is volumeControlFadeToOrange
} else if([[animation valueForKey:@"animationID"] isEqual:@"throbUp"]) {
//animation is throbUp
} else {
//something else
}
}
|
转载自:http://stackoverflow.com/questions/1255086/how-to-identify-caanimation-within-the-animationdidstop-delegate