Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Instagram-like heartbeat animation using CABasicAnimation & CAAnimationGroup
NSMutableArray *animations = [NSMutableArray array];
// Step 1
{
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
animation.toValue = @(1.3);
animation.duration = 0.3;
animation.fillMode = kCAFillModeForwards;
[animations addObject:animation];
}
{
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
animation.toValue = @(1.0);
animation.duration = 0.3;
animation.fillMode = kCAFillModeForwards;
[animations addObject:animation];
}
// Step 2
{
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
animation.toValue = @(1);
animation.beginTime = 0.3;
animation.duration = 0.1;
animation.fillMode = kCAFillModeForwards;
[animations addObject:animation];
}
// Step 3
{
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
animation.toValue = @(1.3);
animation.beginTime = 0.4;
animation.duration = 0.3;
animation.fillMode = kCAFillModeForwards;
[animations addObject:animation];
}
{
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
animation.toValue = @(0);
animation.beginTime = 0.4;
animation.duration = 0.3;
animation.fillMode = kCAFillModeForwards;
[animations addObject:animation];
}
CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
animationGroup.animations = animations;
animationGroup.duration = 0.7;
animationGroup.fillMode = kCAFillModeForwards;
animationGroup.removedOnCompletion = YES;
[self.heartPopup.layer addAnimation:animationGroup forKey:nil];
@Pratik948
Copy link

Pratik948 commented Jan 12, 2017

thanks man

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment