Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pratik948/4b0236d260e48991bd60a312788411d2 to your computer and use it in GitHub Desktop.
Save Pratik948/4b0236d260e48991bd60a312788411d2 to your computer and use it in GitHub Desktop.
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];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment