-
Notifications
You must be signed in to change notification settings - Fork 183
Open
Description
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.
YLProgressBar/YLProgressBar/YLProgressBar.m
Lines 326 to 342 in c7b29a6
| - (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;YLProgressBar/YLProgressBar/YLProgressBar.m
Lines 227 to 230 in c7b29a6
| - (void)setProgress:(CGFloat)progress | |
| { | |
| [self setProgress:progress animated:NO]; | |
| } |
YLProgressBar/YLProgressBar/YLProgressBar.m
Lines 287 to 322 in c7b29a6
| - (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.
yhjiang
Metadata
Metadata
Assignees
Labels
No labels