Last active
December 12, 2015 03:58
-
-
Save C4Code/4710459 to your computer and use it in GitHub Desktop.
Example of using a C4Slider to control the strokeEnd value of a C4Shape. Also highlights the use of the [C4Math sin:] method.
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.h | |
// | |
// Created by Travis Kirton. | |
// | |
#import "C4CanvasController.h" | |
@interface C4WorkSpace : C4CanvasController | |
-(void)adjustPathShape:(C4Slider *)sender; | |
@end |
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 | |
// | |
// Created by Travis Kirton. | |
// | |
#import "C4WorkSpace.h" | |
@implementation C4WorkSpace { | |
C4Slider *slider; | |
C4Shape *pathShape; | |
} | |
-(void)setup { | |
[self createAndAddSinShape]; | |
slider = [[C4Slider alloc] initWithFrame:CGRectMake(0, 0, 400, 44)]; | |
slider.center = self.canvas.center; | |
slider.thumbImage = [C4Image imageNamed:@"pyramid"]; | |
slider.minimumTrackTintColor = C4RED; | |
[self.canvas addSubview:slider]; | |
[slider runMethod:@"adjustPathShape:" target:self forEvent:VALUECHANGED]; | |
} | |
-(void)createAndAddSinShape { | |
NSInteger width = (NSInteger)self.canvas.width; | |
NSInteger stepWidth = 8; | |
NSInteger steps = width / stepWidth +1; | |
CGPoint p[steps]; | |
for(int currentStep = 0; currentStep < steps; currentStep++) { | |
CGFloat x = currentStep * stepWidth; | |
CGFloat y = [C4Math sin:(x / self.canvas.width)*TWO_PI*2]*100; | |
p[currentStep] = CGPointMake(x,y); | |
} | |
pathShape = [C4Shape polygon:p pointCount:steps]; | |
pathShape.userInteractionEnabled = NO; | |
pathShape.center = self.canvas.center; | |
pathShape.fillColor = [UIColor clearColor]; | |
pathShape.strokeEnd = slider.value; | |
pathShape.lineCap = CAPROUND; | |
[self.canvas addShape:pathShape]; | |
} | |
-(void)adjustPathShape:(C4Slider *)sender { | |
if(pathShape.strokeEnd != slider.value) | |
pathShape.strokeEnd = sender.value; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment