2010-06-17 18 views
7

tengo este código en mi método drawRectdrawRect no se actualiza la pantalla

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; 

     } 

Estoy llamando a un método que utiliza NSTimer como esto

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

aquí es el refreshUIView

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

El problema es que drawRect no está borrando la pantalla, está por escribir lo que se escribió la última vez en scree norte.

Respuesta

5

Llama esto temprano en drawRect: una vez que entiendes el contexto.

CGContextClearRect(context , [self bounds]); 

O llame [super drawRect:]; si se establece clearsContextBeforeDrawing.

+4

acaba de encontrar esa configuración Opaque: NO a esa UIView actualizará drawRect automáticamente. – coure2011