coure2011
coure2011

Reputation: 42444

drawRect is not refreshing the screen

I have this code in my drawRect method

float aValue = .0167f;
float fValue = 20;
for(int i=1; i<=6; i++)
        {

            CGContextSelectFont(context, "Arial", fValue, kCGEncodingMacRoman);
            CGContextSetCharacterSpacing(context, 0);
            CGContextSetTextDrawingMode(context, kCGTextFill);

            NSString *hString = [[NSString alloc] initWithFormat:@"%i",i];


            CGContextSetRGBFillColor(context, 1, 1, 1, aValue);
            CGContextShowTextAtPoint(context, i*25, i*16, [hString UTF8String], [hString length]);
            aValue += 0.167;
            fValue += 1;

        }

I am calling a method using NSTimer like this

staticTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(refreshUIView) userInfo:nil repeats:YES];

here is the refreshUIView

-(void)refreshUIView
{
    [self setNeedsDisplay];
}

Problem is that drawRect is not clearing the screen, its just over writing what have been written last time on screen.

Upvotes: 7

Views: 1347

Answers (1)

drawnonward
drawnonward

Reputation: 53669

Call this early in drawRect: once you get the context.

CGContextClearRect( context , [self bounds] );

Or call [super drawRect:]; if clearsContextBeforeDrawing is set.

Upvotes: 5

Related Questions