Skip to content

Instantly share code, notes, and snippets.

@C4Examples
Created July 26, 2012 17:11
Show Gist options
  • Select an option

  • Save C4Examples/3183269 to your computer and use it in GitHub Desktop.

Select an option

Save C4Examples/3183269 to your computer and use it in GitHub Desktop.
Animated Line Dash Pattern 2
//
// C4WorkSpace.m
// Examples
//
// Created by Travis Kirton
//
#import "C4WorkSpace.h"
@interface C4WorkSpace ()
-(void)animate;
@end
@implementation C4WorkSpace {
C4Shape *circle;
CGFloat patternWidth;
}
-(void)setup {
//create the circle and center it
circle = [C4Shape ellipse:CGRectMake(0, 0, 200, 200)];
circle.center = self.canvas.center;
//create a dash pattern
//this pattern is [1,2,3,..,628];
CGFloat dashPattern[628];
int i;
for(i = 0; i < 628; i++) {
dashPattern[i] = i+1;
patternWidth += i;
}
//thicken the line and set its dash pattern
circle.lineWidth = 30.0f;
circle.fillColor = [UIColor clearColor];
[circle setDashPattern:dashPattern pointCount:1260];
//add the line to the canvas
[self.canvas addShape:circle];
//animate it after a short delay
[self runMethod:@"animate" afterDelay:0.1f];
}
-(void)animate {
//duration = 5 minutes (60s * 3 = 180);
circle.animationDuration = 180.0f;
circle.animationOptions = AUTOREVERSE;
circle.strokeColor = C4BLUE;
//set the final dash phase to the entire width of the pattern
circle.lineDashPhase = patternWidth;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment