Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using CALayer as a background for other NSViews

I have an application with an NSTableView in a window. I want to use a CALayer as the background for the entire window, and the table view. In all my my experiments so far, the CALayer always draws over the NSTableView, which is not the effect I'm looking for. Is there a way to make this work, or am I simply out of luck due to the nature of layer-hosting views vs NSViews?

My test setup is a window with the usual NSScrollView/NSTableView combo, and a sibling NSView behind it in the view order. The NSView is set to be layer-hosting with my custom layer within it (just a layer with a backgroundColor set). I've experimented with setting the window's content view to be layer-backed, as well as the table view itself, as well as wrapping the NSScrollView in a layer-backed NSView. The result is always the same.

Thanks for any insight you might be able to provide.

like image 834
Adam Preble Avatar asked Feb 29 '12 18:02

Adam Preble


1 Answers

It is simple. all overlapping views or layers should be layer backing or layer hosting for correct ordering.

you can set [tableview setWantsLayer:YES]
or simply check it in the layers tab when editing the interface.

like image 121
Remizorrr Avatar answered Sep 29 '22 12:09

Remizorrr