Search code examples
swiftmacoscore-graphicscalayercgcontext

Rendering a CALayer's contents that Appear outside of Window


So I've got a big CALayer in an NSView that is larger than my window (using Cocoa on Mac OS X).

Every time I use renderInContext: the only thing that renders is what's viewable in the window, and nothing outside it.

How can I create a bitmap of something outside my visible Rect and export it as a PNG?

I've looked at a bunch of Core Graphics methods but can't find the answer anywhere:(


Solution

  • This turned out to be really easy

    myLayer.masksToBounds = false
    

    This removes the mask the main window puts on the CALayer and allows it to be exported, even though you can't see it.