From 55c94d9827401a931041ebb2bad5ea89280c6d3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=85=A7=E9=97=AB?= <2236368544@qq.com> Date: Sat, 19 Aug 2017 16:07:22 +0800 Subject: [PATCH] Fix #51 if the ture value is farstly bigger than the max value ,the demo will continue draw the progress line ,which will lead to the serious memeory warning of iPhone simulator --- Pod/Classes/MBCircularProgressBarLayer.m | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Pod/Classes/MBCircularProgressBarLayer.m b/Pod/Classes/MBCircularProgressBarLayer.m index 0b1718a..5974180 100644 --- a/Pod/Classes/MBCircularProgressBarLayer.m +++ b/Pod/Classes/MBCircularProgressBarLayer.m @@ -119,10 +119,20 @@ - (void)drawProgressBar:(CGRect)rect context:(CGContextRef)c{ radius = radius - self.emptyLineWidth - self.progressLineWidth/2.f; } + CGFloat currentSelfValue = self.value; + CGFloat currentSelfMaxValue = self.maxValue; + + if (currentSelfValue >= currentSelfMaxValue) { + currentSelfValue = currentSelfMaxValue;//Avoid to draw the progress line repeatly. + } + CGMutablePathRef arc = CGPathCreateMutable(); - CGPathAddArc(arc, NULL, - center.x, center.y, radius, - (self.progressAngle/100.f)*M_PI-((-self.progressRotationAngle/100.f)*2.f+0.5)*M_PI-(2.f*M_PI)*(self.progressAngle/100.f)*(100.f-100.f*self.value/self.maxValue)/100.f, + CGPathAddArc(arc, + NULL, + center.x, + center.y, + radius, + (self.progressAngle/100.f)*M_PI-((-self.progressRotationAngle/100.f)*2.f+0.5)*M_PI-(2.f*M_PI)*(self.progressAngle/100.f)*(100.f-100.f*currentSelfValue/currentSelfMaxValue)/100.f, -(self.progressAngle/100.f)*M_PI-((-self.progressRotationAngle/100.f)*2.f+0.5)*M_PI, YES);