Merge pull request #158 from dredful/master
Added a method to allow the update of both the current and the total for...
Showing
2 changed files
with
12 additions
and
3 deletions
| @@ -23,6 +23,7 @@ typedef NS_ENUM (NSUInteger, PNChartFormatType) { | @@ -23,6 +23,7 @@ typedef NS_ENUM (NSUInteger, PNChartFormatType) { | ||
| 23 | - (void)strokeChart; | 23 | - (void)strokeChart; |
| 24 | - (void)growChartByAmount:(NSNumber *)growAmount; | 24 | - (void)growChartByAmount:(NSNumber *)growAmount; |
| 25 | - (void)updateChartByCurrent:(NSNumber *)current; | 25 | - (void)updateChartByCurrent:(NSNumber *)current; |
| 26 | +- (void)updateChartByCurrent:(NSNumber *)current byTotal:(NSNumber *)total; | ||
| 26 | - (id)initWithFrame:(CGRect)frame | 27 | - (id)initWithFrame:(CGRect)frame |
| 27 | total:(NSNumber *)total | 28 | total:(NSNumber *)total |
| 28 | current:(NSNumber *)current | 29 | current:(NSNumber *)current |
| @@ -206,13 +206,20 @@ displayCountingLabel:(BOOL)displayCountingLabel | @@ -206,13 +206,20 @@ displayCountingLabel:(BOOL)displayCountingLabel | ||
| 206 | 206 | ||
| 207 | 207 | ||
| 208 | -(void)updateChartByCurrent:(NSNumber *)current{ | 208 | -(void)updateChartByCurrent:(NSNumber *)current{ |
| 209 | + | ||
| 210 | + [self updateChartByCurrent:current | ||
| 211 | + byTotal:_total]; | ||
| 212 | + | ||
| 213 | +} | ||
| 214 | + | ||
| 215 | +-(void)updateChartByCurrent:(NSNumber *)current byTotal:(NSNumber *)total { | ||
| 209 | // Add animation | 216 | // Add animation |
| 210 | CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; | 217 | CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; |
| 211 | pathAnimation.duration = self.duration; | 218 | pathAnimation.duration = self.duration; |
| 212 | pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; | 219 | pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; |
| 213 | pathAnimation.fromValue = @([_current floatValue] / [_total floatValue]); | 220 | pathAnimation.fromValue = @([_current floatValue] / [_total floatValue]); |
| 214 | - pathAnimation.toValue = @([current floatValue] / [_total floatValue]); | 221 | + pathAnimation.toValue = @([current floatValue] / [total floatValue]); |
| 215 | - _circle.strokeEnd = [current floatValue] / [_total floatValue]; | 222 | + _circle.strokeEnd = [current floatValue] / [total floatValue]; |
| 216 | 223 | ||
| 217 | if (_strokeColorGradientStart) { | 224 | if (_strokeColorGradientStart) { |
| 218 | self.gradientMask.strokeEnd = _circle.strokeEnd; | 225 | self.gradientMask.strokeEnd = _circle.strokeEnd; |
| @@ -221,10 +228,11 @@ displayCountingLabel:(BOOL)displayCountingLabel | @@ -221,10 +228,11 @@ displayCountingLabel:(BOOL)displayCountingLabel | ||
| 221 | [_circle addAnimation:pathAnimation forKey:@"strokeEndAnimation"]; | 228 | [_circle addAnimation:pathAnimation forKey:@"strokeEndAnimation"]; |
| 222 | 229 | ||
| 223 | if (_displayCountingLabel) { | 230 | if (_displayCountingLabel) { |
| 224 | - [self.countingLabel countFrom:fmin([_current floatValue], [_total floatValue]) to:fmin([current floatValue], [_total floatValue]) withDuration:self.duration]; | 231 | + [self.countingLabel countFrom:fmin([_current floatValue], [_total floatValue]) to:fmin([current floatValue], [total floatValue]) withDuration:self.duration]; |
| 225 | } | 232 | } |
| 226 | 233 | ||
| 227 | _current = current; | 234 | _current = current; |
| 235 | + _total = total; | ||
| 228 | } | 236 | } |
| 229 | 237 | ||
| 230 | @end | 238 | @end |
-
Please register or login to post a comment