开发者

drawRect is not refreshing the screen

开发者 https://www.devze.com 2023-01-03 23:27 出处:网络
I have this code in my drawRect method float aValue = .0167f; float fValue = 20; for(int i=1; i<=6; i++)

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];


            CGContextSet开发者_StackOverflow社区RGBFillColor(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.


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

CGContextClearRect( context , [self bounds] );

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

0

精彩评论

暂无评论...
验证码 换一张
取 消