Created
April 26, 2012 12:03
-
-
Save odrobnik/2499146 to your computer and use it in GitHub Desktop.
Convenience methods to add and animate a shadowPath
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)addShadowWithColor:(UIColor *)color alpha:(CGFloat)alpha radius:(CGFloat)radius offset:(CGSize)offset | |
{ | |
self.layer.shadowOpacity = alpha; | |
self.layer.shadowRadius = radius; | |
self.layer.shadowOffset = offset; | |
if (color) | |
{ | |
self.layer.shadowColor = [color CGColor]; | |
} | |
// cannot have masking | |
self.layer.masksToBounds = NO; | |
} | |
- (void)updateShadowPathToBounds:(CGRect)bounds withDuration:(NSTimeInterval)duration | |
{ | |
CGPathRef oldPath = self.layer.shadowPath; | |
CGPathRef newPath = CGPathCreateWithRect(bounds, NULL); | |
if (oldPath && duration>0) | |
{ | |
CABasicAnimation *theAnimation = [CABasicAnimation animationWithKeyPath:@"shadowPath"]; | |
theAnimation.duration = duration; | |
theAnimation.fromValue = (__bridge id)oldPath; | |
theAnimation.toValue = (__bridge id)newPath; | |
theAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; | |
[self.layer addAnimation:theAnimation forKey:@"shadowPath"]; | |
} | |
self.layer.shadowPath = newPath; | |
CGPathRelease(newPath); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment