Skip to content

Instantly share code, notes, and snippets.

@shawnwall
Created April 17, 2015 16:32
Show Gist options
  • Save shawnwall/cacf727679f3794eba5d to your computer and use it in GitHub Desktop.
Save shawnwall/cacf727679f3794eba5d to your computer and use it in GitHub Desktop.
- (void)drawRect:(CGRect)rect {
//draw the base
UIBezierPath* baseArc = [UIBezierPath bezierPathWithArcCenter:CGPointMake(CGRectGetWidth(self.bounds) / 2, CGRectGetHeight(self.bounds) / 2)
radius:self.bounds.size.height/2-24
startAngle:DEGREES_TO_RADIANS(180)
endAngle:DEGREES_TO_RADIANS(360)
clockwise:YES];
[[UIColor grayColor] setStroke];
baseArc.lineWidth = 24;
[baseArc stroke];
UIBezierPath* progressArc = [UIBezierPath bezierPathWithArcCenter:CGPointMake(CGRectGetWidth(self.bounds) / 2, CGRectGetHeight(self.bounds) / 2)
radius:self.bounds.size.height/2-24
startAngle:DEGREES_TO_RADIANS(180)
endAngle:DEGREES_TO_RADIANS(340)
clockwise:YES];
[[UIColor greenColor] setStroke];
progressArc.lineWidth = 24;
[progressArc stroke];
//testing ball draw
CGRect imageRect = CGRectMake(0, 0, 20, 20);
CAShapeLayer *markerLayer = [CAShapeLayer layer];
UIImage *marker = [UIImage imageNamed:@"shortcuts_library"];
markerLayer.contents = (__bridge id)[marker CGImage];
markerLayer.bounds = imageRect;
markerLayer.position = CGPointMake(0,0);
UIBezierPath * markerPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(CGRectGetWidth(self.bounds) / 2, CGRectGetHeight(self.bounds) / 2)
radius:self.bounds.size.height/2-24
startAngle:DEGREES_TO_RADIANS(180)
endAngle:DEGREES_TO_RADIANS(250)
clockwise:YES];
CGPathRef animatePath = [markerPath CGPath];
CAKeyframeAnimation * arcToRideAnimation;
arcToRideAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
arcToRideAnimation.delegate = self;
arcToRideAnimation.path = animatePath;
arcToRideAnimation.rotationMode = kCAAnimationRotateAutoReverse;
arcToRideAnimation.duration = 0.0;
arcToRideAnimation.fillMode = kCAFillModeForwards;
arcToRideAnimation.autoreverses = NO;
arcToRideAnimation.removedOnCompletion = NO;
arcToRideAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
[markerLayer addAnimation:arcToRideAnimation forKey:@"test"];
[self.layer addSublayer:markerLayer];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment