drawRect не обновляет экран

У меня есть этот код в моем drawRect методе

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;

        }

Я называю метод с помощью NSTimer как это

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

вот refreshUIView

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

Проблема состоит в том, что drawRect не очищает экран, его только по записи, что было записано в прошлый раз на экране.

7
задан coure2011 17 June 2010 в 07:13
поделиться

1 ответ

Вызовите это в начале drawRect: , как только получите контекст.

CGContextClearRect( context , [self bounds] );

Или вызовите [super drawRect:]; , если установлено clearsContextBeforeDrawing .

5
ответ дан 7 December 2019 в 12:14
поделиться