Created
September 14, 2011 14:05
-
-
Save odrobnik/1216647 to your computer and use it in GitHub Desktop.
Dropping a shadow
This file contains 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)animationDidStop:(CABasicAnimation *)anim finished:(BOOL)flag | |
{ | |
self.layer.shadowPath = (CGPathRef)anim.toValue; | |
} | |
- (void)updateShadowWithDuration:(NSTimeInterval)duration | |
{ | |
CALayer *layer = self.layer; | |
if (_dropShadow) | |
{ | |
layer.shadowColor = [UIColor blackColor].CGColor; | |
layer.shadowOffset = CGSizeMake(0,0); | |
layer.shadowOpacity = 0.9; | |
layer.shadowRadius = 10; | |
UIBezierPath *path = [UIBezierPath bezierPathWithRect:self.bounds]; | |
if (layer.shadowPath && duration>0) | |
{ | |
NSLog(@"animate: %@", self); | |
// need animation | |
CABasicAnimation *theAnimation = [CABasicAnimation animationWithKeyPath:@"shadowPath"]; | |
theAnimation.duration = duration; | |
theAnimation.fromValue = (id)layer.shadowPath; | |
theAnimation.toValue = (id)path.CGPath; | |
theAnimation.delegate = self; | |
theAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; | |
theAnimation.removedOnCompletion = NO; | |
[layer addAnimation:theAnimation forKey:@"shadowPath"]; | |
} | |
else | |
{ | |
layer.shadowPath = path.CGPath; | |
} | |
} | |
else | |
{ | |
// no shadow | |
layer.shadowOpacity = 0; | |
layer.shadowPath = NULL; | |
return; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment