Why is my CGContext bound to borders?

Should I override drawInContext () and push outside my CALayer? Although my layer has maskToBounds set to NO (the default), my drawInContext () is called with a clip set to the borders of my layer, and I cannot paint outside of it.

My test layer does something like this:

-(void)drawInContext:(CGContextRef)context 
{   
    [super drawInContext:context];      
    NSLog(@"mask to bounds=%d", self.masksToBounds); // NO  
    CGRect clip = CGContextGetClipBoundingBox(context);
    NSLog(@"clip=%f,%f,%f,%f", clip.origin.x, clip.origin.y, clip.size.width, clip.size.height); // reports the bounds

    CGContextSetStrokeColorWithColor(context, [[UIColor whiteColor] CGColor]);  
    CGContextBeginPath(context);
    CGContextSetLineWidth(context, 5.0);
    CGContextMoveToPoint(context, 0, 0);
    CGContextAddLineToPoint(context, 500, 0.0); // wider than my layer...
    CGContextStrokePath(context);
}

and here is how I installed it:

- (void)viewDidLoad 
{
    [super viewDidLoad];
    CALayer *layer = [[MyLayer alloc] init];
    layer.needsDisplayOnBoundsChange=YES;
    layer.frame = CGRectMake(50, 50, 200, 200);
    [self.view.layer addSublayer:layer];
}

Is this just a limitation of the main layers of animation? (Do I need to draw a layer above this layer?)

thank.

+3
source share
1 answer

, ; , , , masksToBounds NO ( ).

+4

Source: https://habr.com/ru/post/1758554/


All Articles