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.
First of all, thank yannickl for this awesome project.
We imported the version
3.10.2into our project, and found that thedeallocmethod was never called.I found the
_progressTargetTimermay never be invalid if the progress didn't reach the end.YLProgressBar/YLProgressBar/YLProgressBar.m
Lines 326 to 342 in c7b29a6
So I wrote this in the host view's
deallocmethod to invalidate the_progressTargetTimer:_progressBar.progress = 0;YLProgressBar/YLProgressBar/YLProgressBar.m
Lines 227 to 230 in c7b29a6
YLProgressBar/YLProgressBar/YLProgressBar.m
Lines 287 to 322 in c7b29a6
The
deallocmethod was called finally.