samedi 18 juin 2016

Is it possible draw CGContext in blocks?


On IOS, I have a NSArray stores blocks that drawing something on the UIView, for example :

^(CGContextRef ctx) {
    // drawing rectangle
    CGRect rect = CGRectMake(0, 0, 300, 300);
    CGContextSetRGBFillColor(ctx, 1, 0, 0, 1);
    CGContextFillRect(ctx, rect);
    CGContextStrokeRect(ctx, rect);
};

There would be several blocks stored in the array, and I expect those block execute sequently when drawRect got invoked, here's my drawRect

- (void)drawRect:(CGRect)rect {
    // execute blocks 
    for(NSDictionary * task in drawTaskQueue)
    {
        DrawTaskBlock block = [task objectForKey:@"block"];
        block(args, UIGraphicsGetCurrentContext());
    }
}

But when I run the code, I'm sure the blocks got executed without any error, but nothing is showing up. Did I missed something ?


Aucun commentaire:

Enregistrer un commentaire