Objective C drawlayer增加记忆力

时间:2014-05-09 09:10:34

标签: ios objective-c

我的应用正在使用此方法

-(void) drawLayer:(CALayer *)layer inContext:(CGContextRef)context 

这会导致内存消耗增加,并且当出现相应视图时,内存使用量会增加10Mb。即使取消控制器/视图,它也永远不会减少。

我的项目是ARC。任何人都可以帮我弄清楚,问题是什么。 问候 这是代码:`

-(void) drawLayer:(CALayer *)layer inContext:(CGContextRef)context{

    //    CGContextRef context =ctx;// UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
//    CGContextSetLineCap(context, kCGLineCapSquare);

if (self.achievementObj.isComplete) {
    CGContextSetStrokeColorWithColor(context, RED_COLOR.CGColor); //change color here
}
else{
    CGContextSetStrokeColorWithColor(context, BLUE_COLOR.CGColor); //change color here

}

CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
CGFloat lineWidth = Width_circle; //change line width here
CGContextSetLineWidth(context, lineWidth);

CGContextMoveToPoint(context,0 ,Y_DRAW+BOUNDS_CIRCLE/2);
if (self.index!=0)
{
    CGContextMoveToPoint(context,0 ,Y_DRAW+BOUNDS_CIRCLE/2);
    AchievementObj *achievementObj = [self.arrAchievement objectAtIndex:self.index-1];
    if (achievementObj.isComplete) {
        CGContextSetStrokeColorWithColor(context, RED_COLOR.CGColor);
    }
    else{
        CGContextSetStrokeColorWithColor(context, BLUE_COLOR.CGColor);
    }
    CGContextAddLineToPoint(context,X_DRAW+BOUNDS_CIRCLE  ,Y_DRAW+BOUNDS_CIRCLE/2);
    CGContextStrokePath(context);
}

if (self.achievementObj.isComplete)
{
    CGContextSetStrokeColorWithColor(context, RED_COLOR.CGColor); //change color here
}
else{
    CGContextSetStrokeColorWithColor(context, BLUE_COLOR.CGColor); //change color here

}

CGContextMoveToPoint(context,X_DRAW+BOUNDS_CIRCLE ,Y_DRAW+BOUNDS_CIRCLE/2);
if (self.isTheFirstAchievement)
{
    if (self.isTheLastAchievement) {

    }
    else
        CGContextAddLineToPoint(context,320  ,Y_DRAW+BOUNDS_CIRCLE/2);
}
else if (self.isTheLastAchievement ) {
    CGContextAddLineToPoint(context,60 ,Y_DRAW+BOUNDS_CIRCLE/2);
}
else{
    CGContextAddLineToPoint(context,320  ,Y_DRAW+BOUNDS_CIRCLE/2);
}

CGContextStrokePath(context);

if (self.achievementObj.isComplete)
{
    CGContextSetStrokeColorWithColor(context, RED_COLOR.CGColor);
}
else
{
    CGContextSetStrokeColorWithColor(context, BLUE_COLOR.CGColor);
}

CGContextMoveToPoint(context,X_DRAW+BOUNDS_CIRCLE ,Y_DRAW+BOUNDS_CIRCLE/2);
if (self.isTheFirstAchievement) {
    if (self.isTheLastAchievement) {

    }
    else
        CGContextAddLineToPoint(context,320  ,Y_DRAW+BOUNDS_CIRCLE/2);

}
else   if (self.isTheLastAchievement) {
    CGContextAddLineToPoint(context,60  ,Y_DRAW+BOUNDS_CIRCLE/2);
}

else{
    CGContextAddLineToPoint(context,320  ,Y_DRAW+BOUNDS_CIRCLE/2);
}

CGContextStrokePath(context);

//    CGFloat lineWidth = Width_circle; //change line width here
if ((self.achievementObj.arrSteps.count>0) &&(![self.tbView isEditing]))
{
    //        StepObj *stepObj=[self.achievementObj.arrSteps objectAtIndex:0];
    if (self.achievementObj.isComplete) {
        CGContextSetStrokeColorWithColor(context, RED_COLOR.CGColor);
    }
    else
    {
        CGContextSetStrokeColorWithColor(context, BLUE_COLOR.CGColor);
    }
    CGContextSetLineWidth(context, 2);
    CGContextMoveToPoint(context,X_DRAW +BOUNDS_CIRCLE/2,Y_DRAW+BOUNDS_CIRCLE);
    CGContextAddLineToPoint(context,X_DRAW+BOUNDS_CIRCLE/2,Y_DRAW+BOUNDS_CIRCLE+self.currentHeight+4);
    CGContextStrokePath(context);

}
if (self.achievementObj.isComplete)
{
    CGContextSetStrokeColorWithColor(context, RED_COLOR.CGColor);
}
else{
    CGContextSetStrokeColorWithColor(context, BLUE_COLOR.CGColor);
}

CGContextFillEllipseInRect(context, CGRectMake(X_DRAW, Y_DRAW, BOUNDS_CIRCLE, BOUNDS_CIRCLE));
CGContextAddEllipseInRect(context, CGRectMake(X_DRAW, Y_DRAW, BOUNDS_CIRCLE, BOUNDS_CIRCLE));
CGContextAddEllipseInRect(context, CGRectMake(X_DRAW+1, Y_DRAW+1, BOUNDS_CIRCLE-2, BOUNDS_CIRCLE-2));
//...
CGContextTranslateCTM(context, 0,0);
CGContextScaleCTM(context, 1, -1);
CGContextSetRGBFillColor(context, 0,0,0, 1.0);
CGContextSetLineWidth(context, 6.0);
CGContextSelectFont(context, "Lato-Light", 25.0, kCGEncodingMacRoman);

CGContextSetCharacterSpacing(context, 1.7);
CGContextSetTextDrawingMode(context, kCGTextFill);
NSString *str=[NSString stringWithFormat:@"%d",self.index+1];
CGContextShowTextAtPoint(context, X_DRAW + BOUNDS_CIRCLE/3+10-str.length*10, -(Y_DRAW+BOUNDS_CIRCLE/1.5), [str UTF8String], str.length);

CGContextStrokePath(context);
CGContextRestoreGState(context);
//    context = nil
//    CGContextRelease(context);

}`

0 个答案:

没有答案