Skip to content

Instantly share code, notes, and snippets.

@rais38
Created October 26, 2013 15:35
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 rais38/7170792 to your computer and use it in GitHub Desktop.
Save rais38/7170792 to your computer and use it in GitHub Desktop.
Add gradient animation
- (void)addGradientAnimation
{
UIColor *color1 = [UIColor redColor];
UIColor *color2 = [UIColor yellowColor];
UIColor *color3 = [UIColor grayColor];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = self.view.frame;
gradient.colors = @[(id)color1.CGColor, (id)color2.CGColor, (id)color2.CGColor];
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"colors"];
animation.toValue = @[(id)color3.CGColor, (id)color1.CGColor, (id)color1.CGColor];
animation.duration = 3.0;
animation.autoreverses = YES;
animation.repeatCount = HUGE_VALF;
[gradient addAnimation:animation forKey:@"colors"];
[self.view.layer addSublayer:gradient];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment