Created
June 17, 2013 07:20
-
-
Save motoishmz/5795161 to your computer and use it in GitHub Desktop.
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
- (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