7
我有这样的代码在我的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没有清理屏幕,只是写了上次写在屏幕上的内容ñ。
刚发现设置为Opaque:NO,UIView会自动刷新drawRect。 – coure2011 2010-06-17 07:58:41