Skip to content

Commit

Permalink
Fix dealloc crash
Browse files Browse the repository at this point in the history
  • Loading branch information
joanromano committed Apr 17, 2014
1 parent f530bf6 commit 6734ee9
Showing 1 changed file with 15 additions and 34 deletions.
49 changes: 15 additions & 34 deletions Source/CADVoteCountView.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ @interface CADLinearVoteCountView : CADVoteCountView

@end

/**************** Abstract CADVoteCountView ****************/
/**************** Abstract CADVoteCountView ****************/

@implementation CADVoteCountView

Expand Down Expand Up @@ -155,45 +155,22 @@ - (UIColor *)colorFromAngle:(NSUInteger)newAngle
return [UIColor colorWithRed:red green:green blue:0 alpha:1];
}

#pragma mark - Lazy

- (CAAnimationGroup *)colorPathGroupAnimation
{
if (!_colorPathGroupAnimation)
{
_colorPathGroupAnimation = [CAAnimationGroup animation];
_colorPathGroupAnimation.animations = @[self.colorPathStrokeColorAnimation, self.colorPathStrokeEndAnimation];
_colorPathGroupAnimation.duration = kAnimationDuration;
}

return _colorPathGroupAnimation;
}

- (CAKeyframeAnimation *)colorPathStrokeColorAnimation
- (void)setupAnimationGroup
{
if (!_colorPathStrokeColorAnimation)
{
_colorPathStrokeColorAnimation = [CAKeyframeAnimation animationWithKeyPath:@"strokeColor"];
_colorPathStrokeColorAnimation.duration = kAnimationDuration;
}
self.colorPathStrokeColorAnimation = [CAKeyframeAnimation animationWithKeyPath:@"strokeColor"];
self.colorPathStrokeColorAnimation.duration = kAnimationDuration;

return _colorPathStrokeColorAnimation;
}

- (CAKeyframeAnimation *)colorPathStrokeEndAnimation
{
if (!_colorPathStrokeEndAnimation)
{
_colorPathStrokeEndAnimation = [CAKeyframeAnimation animationWithKeyPath:@"strokeEnd"];
_colorPathStrokeEndAnimation.duration = kAnimationDuration;
}
self.colorPathStrokeEndAnimation = [CAKeyframeAnimation animationWithKeyPath:@"strokeEnd"];
self.colorPathStrokeEndAnimation.duration = kAnimationDuration;

return _colorPathStrokeEndAnimation;
self.colorPathGroupAnimation = [CAAnimationGroup animation];
self.colorPathGroupAnimation.animations = @[self.colorPathStrokeColorAnimation, self.colorPathStrokeEndAnimation];
self.colorPathGroupAnimation.duration = kAnimationDuration;
}

@end

/**************** CADCircularVoteCountView ****************/
/**************** CADCircularVoteCountView ****************/

static NSUInteger const kCircularMaxAngle = 360;
static NSUInteger const kCircularDefaultAngle = 180;
Expand Down Expand Up @@ -246,6 +223,8 @@ - (void)setAngle:(NSUInteger)newAngle animationType:(CADVoteCountViewAnimationTy
CGFloat alpha = newAngle > angle ? newAngle*1.2f : newAngle*0.8f,
maxAngle = (CGFloat)[self maxAngle];

[self setupAnimationGroup];

self.colorPathStrokeEndAnimation.values = @[@(angle / maxAngle),
@(alpha / maxAngle),
@(newAngle / maxAngle)];
Expand Down Expand Up @@ -287,7 +266,7 @@ - (NSUInteger)maxAngle

@end

/**************** CADLinearVoteCountView ****************/
/**************** CADLinearVoteCountView ****************/

static NSUInteger const kLinearMaxAngle = 100;
static NSUInteger const kLinearDefaultAngle = 50;
Expand Down Expand Up @@ -335,6 +314,8 @@ - (void)setAngle:(NSUInteger)newAngle animationType:(CADVoteCountViewAnimationTy
CGFloat alpha = newAngle > angle ? newAngle*1.2f : newAngle*0.8f,
maxAngle = (CGFloat)[self maxAngle];

[self setupAnimationGroup];

self.colorPathStrokeEndAnimation.values = @[@(angle / maxAngle),
@(alpha / maxAngle),
@(newAngle / maxAngle)];
Expand Down

0 comments on commit 6734ee9

Please sign in to comment.