Created
          May 1, 2013 08:26 
        
      - 
      
- 
        Save kenshin03/5494316 to your computer and use it in GitHub Desktop. 
    animating the bouncing "LIKE" image
  
        
  
    
      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
    
  
  
    
  | - (void) likeFeed { | |
| UIImageView * animatedLikeImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"coverfeed-like_button"]]; | |
| animatedLikeImageView.frame = CGRectMake(80.0f, 210.0f, 160.0f, 160.0f); | |
| animatedLikeImageView.contentMode = UIViewContentModeScaleToFill; | |
| self.animatedLikeImageView = animatedLikeImageView; | |
| self.animatedLikeImageView.hidden = YES; | |
| [self.view addSubview:self.animatedLikeImageView]; | |
| double delayInSeconds = .3; | |
| dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); | |
| dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ | |
| self.animatedLikeImageView.hidden = NO; | |
| self.animatedLikeImageView.layer.anchorPoint = CGPointMake(0.50, .5); | |
| CAKeyframeAnimation *bounceAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"]; | |
| bounceAnimation.values = [NSArray arrayWithObjects: | |
| [NSNumber numberWithFloat:0.8], | |
| [NSNumber numberWithFloat:1.5], | |
| [NSNumber numberWithFloat:0.0], | |
| nil]; | |
| bounceAnimation.duration = 0.6; | |
| [bounceAnimation setTimingFunctions:[NSArray arrayWithObjects: | |
| [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault], | |
| [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault], | |
| [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut], | |
| nil]]; | |
| bounceAnimation.fillMode = kCAFillModeForwards; | |
| bounceAnimation.removedOnCompletion = NO; | |
| [self.animatedLikeImageView.layer addAnimation:bounceAnimation forKey:@"bounce"]; | |
| }); | |
| ... | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment