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:
NSClipView
of the NSScrollView
is a special subclass that is a layer hosting view and uses a CAScrollLayer
as the backing layer.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
.
This seems to be an OS X bug. A radar has been filed. In the meanwhile, here's the best workaround I found (where view
is the superview of all of the sibling views):
view.subviews = [view.subviews copy]
Triggering the setter for subviews
sets the proper zPosition
on the view layers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With