Skip to content

Instantly share code, notes, and snippets.

@iosappdeveloper
Created September 29, 2014 00:20
Show Gist options
  • Save iosappdeveloper/f7beaf293ceb6fbc70e6 to your computer and use it in GitHub Desktop.
Save iosappdeveloper/f7beaf293ceb6fbc70e6 to your computer and use it in GitHub Desktop.
UIView border layer color with shadow animation
CALayer *layer = self.downloadContainerView.layer;
layer.shadowOffset = CGSizeMake(2, 2);
layer.shadowColor = [UIColor blackColor].CGColor;
layer.shadowRadius = 4.0f;
layer.shadowPath = [[UIBezierPath bezierPathWithRect:layer.bounds] CGPath];
CABasicAnimation *color = [CABasicAnimation animationWithKeyPath:@"borderColor"];
color.fromValue = (id)[UIColor redColor].CGColor;
color.toValue = (id)[UIColor lightGrayColor].CGColor;
self.downloadContainerView.layer.borderColor = [UIColor lightGrayColor].CGColor;
CABasicAnimation *shadowOpacity = [CABasicAnimation animationWithKeyPath:@"shadowOpacity"];
shadowOpacity.fromValue = @0.3;
shadowOpacity.toValue = @0;
self.downloadContainerView.layer.shadowOpacity = 0;
CAAnimationGroup *both = [CAAnimationGroup animation];
both.duration = 1;
both.animations = @[color, shadowOpacity];
both.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
[self.downloadContainerView.layer addAnimation:both forKey:@"color and shadow"];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment