Created
July 26, 2012 17:11
-
-
Save C4Examples/3183269 to your computer and use it in GitHub Desktop.
Animated Line Dash Pattern 2
This file contains hidden or 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
| // | |
| // 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