Forked from w-i-n-s/gist:2ac5a02237cb32ab93901741e581d24b
          
        
    
          Created
          January 12, 2017 11:54 
        
      - 
      
- 
        Save Pratik948/4b0236d260e48991bd60a312788411d2 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