How to use DrawRect correctly

Im currently creating a custom one UIActivityIndicator. To do this, I created the following direct line function:

-(void) drawRect:(CGRect)rect  
{
CGPoint point;
NSLog(@"here %d",stage);`

CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(ctx, 2.0);

for (int i = 1 ; i<=10; ++i) {


    CGContextSetStrokeColorWithColor(ctx, [[self getColorForStage:stage+i WithAlpha:0.1 *i] CGColor]);
    point = [self pointOnOuterCirecleWithAngel:stage+i];
    CGContextMoveToPoint(ctx, point.x, point.y);
    point = [self pointOnInnerCirecleWithAngel:stage+i];
    CGContextAddLineToPoint( ctx, point.x, point.y);
    CGContextStrokePath(ctx);
}



stage++;
}

And I added NSTimerto call[self setNeedsDisplay];

The animation works fine, but when I import it into my application every time I scroll through the table or do everything, the animation will stop until the table stops moving.

I assume that only after the user interface completes the update, it will update my DrawRect, but how can I get around it or do it right.

+2
source share
3 answers

runloop, , , ( ). .

NSTimer *timer = [NSTimer timerWithTimeInterval:0.1 target:self selector:@selector(setNeedsDisplay) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];

( NSDefaultRunLoopMode NSRunLoopCommonModes.)

+3

[self setNeedsDisplay]; didload

+1

, , . , . , . , , , , . , . , (getColorForStage pointOnOuterCirecleWithAngel), , drawRect?

drawRect . drawRect , , , . , , , . setNeedsDisplay , drawRect, , , , , . , drawRect , , , , .

, drawRect , setNeedsDisplay , .

Core Animation. , Core Animation . , drawRect, Core Animation, - .

0

All Articles