NSVisualEffectView disappears when using a layer-backed view

742 Views Asked by At

My goal

I would like to add a vibrancy effect to a collection view.

The setup

I have the following view hierarchy:

enter image description here

When I use this layout, the background has the vibrancy effect as expected, but the performance is not quite there.

NSCollectionView is optimized to work with layer-backed views, so I enable the CALayer on the collection view's enclosing scroll view.

The problem

If I do this, the visual effect view is no longer visible, and the collection view has a white background.

My question

Is there any way to make a layer-backed view work together with NSVisualEffectView?

1

There are 1 best solutions below

0
On BEST ANSWER

So if anyone's wondering, here's the trick:

  • adding the NSVisualEffectView: correct
  • making the enclosing scroll view layer-backed: correct
  • enabling the scroll view to draw a background: wrong

Make sure to either set drawsBackground to false, or disable it in Interface Builder, and your collection view will have the vibrant background, and fast scrolling as well