Created
September 14, 2016 10:54
-
-
Save w-i-n-s/2ac5a02237cb32ab93901741e581d24b to your computer and use it in GitHub Desktop.
Instagram-like heartbeat animation using CABasicAnimation & CAAnimationGroup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
thanks man