I have a view hierarchy that looks like this:
So basically I have an NSSplitView with a subview that contains a scroll view (for a table view) as well as a footer view that contains 3 subviews. Some important things to note:
- Uses the 10.8 base SDK, no auto layout
- The window content view, the split view, the parent view of the scroll and footer views, and the scroll view and footer view are all layer backed with an NSViewContentsRedrawOnSetNeedsDisplay redraw policy.
- The
NSClipView
of theNSScrollView
is a special subclass that is a layer hosting view and uses aCAScrollLayer
as the backing layer. - The Color View is a simple layer backed view that has a background color set.
- The Background View is a layer-hosting view that has a sublayer with the contents property set to an image (contentsCenter is also set)
- The Content View is a layer backed container view that contains a single subview, a custom layer backed button view (not an NSButton).
- The footer view overlaps the scroll view by about 3 pixels
I'm getting pretty erratic behaviour with this layout. Here are the three distinct scenarios I'm getting, which randomize every time I launch the app.
1) Everything appears OK. Background view and all the content are there:
2) The button appears fine, but the Background View seems to be partially transparent:
3) Background View appears properly but the button is gone:
There is absolutely no code that is changing between each of these scenarios. I just stop and run the app again. I made sure that I'm not changing anything related to opacity at runtime. The only thing I do at runtime is set the background colors and images on the views.
EDIT: I had a feeling that the overlapping views might be causing trouble, so I tested without the overlap and get the same results.
EDIT 2: This seems to be a problem with the zPosition
of the layers of the layer backed views. The order is scrambled and random. If I manually force the zPosition of the layers to the right values to match the subview order, then everything is fine. Unfortunately, I can't find a cleaner way to do this than just setting the zPosition
.