Skip to content

Instantly share code, notes, and snippets.

@w-i-n-s
Created September 14, 2016 10:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save w-i-n-s/2ac5a02237cb32ab93901741e581d24b to your computer and use it in GitHub Desktop.
Save w-i-n-s/2ac5a02237cb32ab93901741e581d24b 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];
@Pratik948
Copy link

thanks man

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