Skip to content

Instantly share code, notes, and snippets.

@fbparis
Created April 6, 2014 02:54
Show Gist options
  • Save fbparis/10000905 to your computer and use it in GitHub Desktop.
Save fbparis/10000905 to your computer and use it in GitHub Desktop.
//
// SunshineLayerView.m
// Sunshine
//
#import "SunshineLayerView.h"
@implementation SunshineLayerView
@synthesize color = _color;
@synthesize count = _count;
- (NSUInteger)count {
if (!_count) _count = 16;
return _count;
}
- (void)setCount:(NSUInteger)count {
_count = count;
[self setNeedsDisplay];
}
- (UIColor *)color {
if (!_color) _color = [[UIColor redColor] colorWithAlphaComponent:0.25];
return _color;
}
- (void)setColor:(UIColor *)color {
_color = [color colorWithAlphaComponent:0.25];
[self setNeedsDisplay];
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self setup];
}
return self;
}
- (void)setup {
self.backgroundColor = nil;
self.opaque = NO;
self.contentMode = UIViewContentModeRedraw;
[self animate];
}
- (void)animate {
[self.layer removeAllAnimations];
[UIView animateWithDuration:4.0
delay:0.0
options:UIViewAnimationOptionBeginFromCurrentState+UIViewAnimationOptionRepeat+UIViewAnimationOptionCurveLinear+UIViewAnimationOptionAllowAnimatedContent+UIViewAnimationOptionAllowUserInteraction
animations:^{
self.transform = CGAffineTransformMakeRotation(-M_PI);
}
completion:nil];
}
- (void)awakeFromNib {
[self setup];
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
UIBezierPath *path =[UIBezierPath bezierPath];
CGPoint center = CGPointMake(rect.size.width / 2.0, rect.size.height / 2.0);
CGFloat radius = sqrt(pow(center.x, 2) + pow(center.y, 2));
CGFloat angle = M_PI / self.count;
[self.color set];
[path moveToPoint:center];
for (NSUInteger i = 0; i < self.count; i++) {
[path addArcWithCenter:center radius:radius startAngle:2*i*angle endAngle:(2*i+1)*angle clockwise:YES];
[path addLineToPoint:center];
[path closePath];
[path fill];
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment