First of all, thank yannickl for this awesome project.
We imported the version 3.10.2
into our project, and found that the dealloc
method was never called.
I found the _progressTargetTimer
may never be invalid if the progress didn't reach the end.
|
- (void)updateProgressWithTimer:(NSTimer *)timer |
|
{ |
|
CGFloat dt_progress = [timer.userInfo floatValue]; |
|
|
|
_progress += dt_progress; |
|
|
|
if ((dt_progress < 0 && _progress <= _progressTargetValue) |
|
|| (dt_progress > 0 && _progress >= _progressTargetValue)) |
|
{ |
|
[_progressTargetTimer invalidate]; |
|
_progressTargetTimer = nil; |
|
|
|
_progress = _progressTargetValue; |
|
} |
|
|
|
[self setNeedsDisplay]; |
|
} |
So I wrote this in the host view's dealloc
method to invalidate the _progressTargetTimer
:
_progressBar.progress = 0;
|
- (void)setProgress:(CGFloat)progress |
|
{ |
|
[self setProgress:progress animated:NO]; |
|
} |
|
- (void)setProgress:(CGFloat)progress animated:(BOOL)animated |
|
{ |
|
@synchronized (self) |
|
{ |
|
if (_progressTargetTimer && [_progressTargetTimer isValid]) |
|
{ |
|
[_progressTargetTimer invalidate]; |
|
} |
|
|
|
CGFloat newProgress = progress; |
|
if (newProgress > 1.0f) |
|
{ |
|
newProgress = 1.0f; |
|
} else if (newProgress < 0.0f) |
|
{ |
|
newProgress = 0.0f; |
|
} |
|
|
|
if (animated) |
|
{ |
|
_progressTargetValue = newProgress; |
|
CGFloat incrementValue = ((_progressTargetValue - _progress) * YLProgressBarStripesAnimationTime) / YLProgressBarProgressTime; |
|
self.progressTargetTimer = [NSTimer timerWithTimeInterval:YLProgressBarStripesAnimationTime |
|
target:self |
|
selector:@selector(updateProgressWithTimer:) |
|
userInfo:[NSNumber numberWithFloat:incrementValue] |
|
repeats:YES]; |
|
[[NSRunLoop currentRunLoop] addTimer:_progressTargetTimer forMode:NSRunLoopCommonModes]; |
|
} else |
|
{ |
|
_progress = newProgress; |
|
|
|
[self setNeedsDisplay]; |
|
} |
|
} |
|
} |
The dealloc
method was called finally.