Skip to content

Instantly share code, notes, and snippets.

@motoishmz
Created June 17, 2013 07:20
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 motoishmz/5795161 to your computer and use it in GitHub Desktop.
Save motoishmz/5795161 to your computer and use it in GitHub Desktop.
- (id)init{
self = [super init];
if (self)
{
self.frame = CGRectMake(0, 0, 100, 100);
self.backgroundColor = [UIColor clearColor];
self.opaque = NO;
}
return self;
}
- (void)layoutSubviews
{
[self setLayerProperties];
[self attachAnimations];
}
- (void)setLayerProperties
{
CAShapeLayer *layer = (CAShapeLayer *)self.layer;
layer.path = [UIBezierPath bezierPathWithOvalInRect:self.bounds].CGPath;
layer.fillColor = [UIColor colorWithHue:0 saturation:1 brightness:.8 alpha:1].CGColor;
}
- (void)attachAnimations
{
[self attachPathAnimation];
[self attachColorAnimation];
}
- (void)attachPathAnimation
{
CABasicAnimation *animation = [self animationWithKeyPath:@"path"];
animation.toValue = (id)[UIBezierPath bezierPathWithOvalInRect:CGRectInset(self.bounds, 40, 40)].CGPath;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[self.layer addAnimation:animation forKey:animation.keyPath];
}
- (void)attachColorAnimation
{
CABasicAnimation *animation = [self animationWithKeyPath:@"fillColor"];
animation.fromValue = (id)[UIColor colorWithHue:0 saturation:.9 brightness:.9 alpha:1].CGColor;
[self.layer addAnimation:animation forKey:animation.keyPath];
}
- (CABasicAnimation *)animationWithKeyPath:(NSString *)keyPath
{
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:keyPath];
animation.autoreverses = YES;
animation.repeatCount = HUGE_VALF;
animation.duration = 1;
return animation;
}
+ (Class)layerClass
{
return [CAShapeLayer class];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment