Skip to content

Commit

Permalink
added delegate pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitch Malleo committed Jan 13, 2016
1 parent d15f480 commit e20adac
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 4 deletions.
13 changes: 12 additions & 1 deletion Classes/VAProgressCircle.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
#define VADefaultGreen [UIColor colorWithRed:35.0/255.0 green:177.0/255.0 blue:70.0/255.0 alpha:1.0f]
#define VADefaultBlue [UIColor colorWithRed:32.0/255.0 green:149.0/255.0 blue:242.0/255.0 alpha:1.0f]

@class VAProgressCircle;

@protocol VAProgressCircleDelegate <NSObject>

- (void)progressCircle:(VAProgressCircle *)circle willAnimateToProgress:(int)progress;
- (void)progressCircle:(VAProgressCircle *)circle didAnimateToProgress:(int)progress;

@end

typedef void (^VAProgressCircleProgressCompletionBlock)(int progress, BOOL isAnimationCompleteForProgress);

typedef NS_ENUM(NSInteger, VAProgressCircleColorTransitionType){
Expand Down Expand Up @@ -39,7 +48,7 @@ typedef NS_ENUM(NSInteger, VAProgressCircleRotationDirection){
@property (strong, nonatomic) UIColor *accentLineColor;
@property (strong, nonatomic) UIColor *numberLabelColor;
@property (strong, nonatomic) UIColor *circleHighlightColor;

@property (strong, nonatomic) UIColor *circleTransitionColor;
@property (strong, nonatomic) UIColor *accentLineTransitionColor;
@property (strong, nonatomic) UIColor *numberLabelTransitionColor;
Expand All @@ -55,4 +64,6 @@ typedef NS_ENUM(NSInteger, VAProgressCircleRotationDirection){

@property (copy, nonatomic) VAProgressCircleProgressCompletionBlock progressBlock;

@property (weak, nonatomic) id<VAProgressCircleDelegate> delegate;

@end
18 changes: 17 additions & 1 deletion Classes/VAProgressCircle.m
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ - (void)setProgress:(int)progress
{
self.progressBlock(progress, NO);
}
else if(self.delegate)
{
[self.delegate progressCircle:self willAnimateToProgress:progress];
}

CAShapeLayer *progressPieceLine = [CAShapeLayer layer];
progressPieceLine.path = self.innerBackgroundPath.CGPath;
Expand Down Expand Up @@ -491,10 +495,14 @@ - (void)addProgressPieceLine:(CAShapeLayer *)progressPieceLine withCurrent:(floa
[lineIsFinishedRetractAnimation setValue:progressPieceLine forKey:kLayer];
[lineIsFinishedRetractAnimation setValue:kProgressPieceLineIsFinishedRetractAnimation forKey:kName];
}
else if(progressCircleIsComplete)
else if(progressCircleIsComplete && self.progressBlock)
{
self.progressBlock(current, YES);
}
else if (progressCircleIsComplete && self.delegate)
{
[self.delegate progressCircle:self didAnimateToProgress:current];
}

[self.progressPieceView.layer addSublayer:progressPieceLine];

Expand Down Expand Up @@ -628,13 +636,21 @@ - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
self.progressBlock([current intValue], YES);
}
else if(self.delegate)
{
[self.delegate progressCircle:self didAnimateToProgress:[current intValue]];
}
}
else if(([name isEqualToString:kProgressPieceInnerToOuterMoveAnimation] && !self.shouldHighlightProgress && !self.shouldShowAccentLine) || ([name isEqualToString:kProgressPieceFlashFadeAnimation] && !self.shouldShowAccentLine) || ([name isEqualToString:kProgressPieceLineFadeAnimation]))
{
if(self.progressBlock)
{
self.progressBlock([current intValue], YES);
}
else if(self.delegate)
{
[self.delegate progressCircle:self didAnimateToProgress:[current intValue]];
}
}
}

Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,25 @@ Use the progessBlock to add functionality to execute before or after a progress
//Add custom block functionality here

};

If you need the delegate pattern, do not implement the block and set your delegate and they will get called insead

- (void)viewDidLoad
{
self.progressCircle.delegate = self;
}

#pragma mark - VAProgressCircleDelegate

- (void)progressCircle:(VAProgressCircle *)circle willAnimateToProgress:(int)progress
{
//Add custom delegate functionality here
}

- (void)progressCircle:(VAProgressCircle *)circle didAnimateToProgress:(int)progress
{
//Add custom delegate functionality here
}

Toggle animation features of the VAProgressCircle.

Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
#import <UIKit/UIKit.h>
#import "VAProgressCircle.h"

@interface MainViewController : UIViewController
@interface MainViewController : UIViewController <VAProgressCircleDelegate>

@end
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ - (void)addChart
[self setPrimaryColorForChart];
[self setTransitionColorForChart];
[self setTransitionTypeForChart];
[self setBlocksForChart];
//self.circleChart.delegate = self;
//[self setBlocksForChart];

[self.view addSubview:self.circleChart];
}
Expand Down Expand Up @@ -244,4 +245,16 @@ - (IBAction)progressChartTransitionTypeSegmentedControlWasTouched:(id)sender
[self setTransitionTypeForChart];
}

#pragma mark - VAProgressCircleDelegate

- (void)progressCircle:(VAProgressCircle *)circle willAnimateToProgress:(int)progress
{
NSLog(@"will animate to progress %i", progress);
}

- (void)progressCircle:(VAProgressCircle *)circle didAnimateToProgress:(int)progress
{
NSLog(@"did animate to progress %i", progress);
}

@end

0 comments on commit e20adac

Please sign in to comment.