CALayer renderInContext not called

I am currently working on a CALayer subclass (on Mac) which is implementing renderInContext to draw the layer's actual content, and noticed that this method is actually never called automatically. Is renderInContext rather supposed to be called manually unlike NSView's drawRect method?


I tried for instance setting CALayer's shouldRasterize = YES, and I am explicitly calling [layer setNeedsDisplay], as well as playing around with the parent NSView's layerContentsRedrawPolicy property, but none of them caused renderInContext ever to be called.

Accepted Reply

I found the problem. The actual method to be implemented for custom layer drawing seems to be drawInContext, not renderInContext:

https://developer.apple.com/documentation/quartzcore/calayer/1410757-drawincontext


@Apple: adding drawInContext to the "See also" section of renderInContext would help to avoid that confusion:

https://developer.apple.com/documentation/quartzcore/calayer/1410909-renderincontext

Replies

I found the problem. The actual method to be implemented for custom layer drawing seems to be drawInContext, not renderInContext:

https://developer.apple.com/documentation/quartzcore/calayer/1410757-drawincontext


@Apple: adding drawInContext to the "See also" section of renderInContext would help to avoid that confusion:

https://developer.apple.com/documentation/quartzcore/calayer/1410909-renderincontext