Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erratic behaviour with layer backed/layer hosting NSViews

I have a view hierarchy that looks like this:

enter image description here

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 the NSScrollView is a special subclass that is a layer hosting view and uses a CAScrollLayer 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:

enter image description here

2) The button appears fine, but the Background View seems to be partially transparent:

enter image description here

3) Background View appears properly but the button is gone:

enter image description here

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.

like image 777
indragie Avatar asked Jan 06 '13 20:01

indragie


1 Answers

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.

like image 145
indragie Avatar answered Nov 08 '22 07:11

indragie