title: How to make NSSplitView collapsing animation smooth?
body: <p>I have a "two-panel selector" or "shoe box" implemented with an <a href="https://developer.apple.com/documentation/appkit/nssplitview" rel="nofollow noreferrer"><code>NSSplitView</code></a> and two <code>NSOutlineView</code>s, one for each split item in the <code>NSSplitView</code>. Basically it looks like this:</p>
  
  <hr>
  
  <p>[Window Toolbar]</p>
  
  <p>| side  |  main  |</p>
  
  <hr>
  
  <p>The sidebar can be toggled by</p>
  
  <pre><code>func toggleSidebar() {
      self.splitViewItems[0].animator().isCollapsed = 
          !self.splitViewItems[0].animator().isCollapsed
  }
  </code></pre>
  
  <h2>The problem</h2>
  
  <p>The animation is not smooth, especially when the "main"'s content are scrolled up below the toolbar (with the translucency effect).</p>
  
  <h2>Attempts</h2>
  
  <p>I have a customized subclass of <a href="https://developer.apple.com/documentation/appkit/nstableheadercell" rel="nofollow noreferrer"><code>NSTableHeaderCell</code></a> with an overriding <a href="https://developer.apple.com/documentation/appkit/nscell/1535830-draw" rel="nofollow noreferrer"><code>draw(withFrame:in:)</code></a>. I noticed the <code>draw(withFrame:in:)</code> method is called (per frame I guess) during the animation.</p>
  
  <p>I also set the <a href="https://developer.apple.com/documentation/appkit/nstableheaderview" rel="nofollow noreferrer"><code>headerView</code></a> of the <code>NSOutlineView</code> to be layer-backed, and set it as:</p>
  
  <pre><code>self.outlineView.headerView!.layerContentsRedrawPolicy = .onSetNeedsDisplay
  self.outlineView.headerView!.layerContentsPlacement = .left
  </code></pre>
  
  <p>Other <a href="https://developer.apple.com/documentation/appkit/nsview.layercontentsredrawpolicy" rel="nofollow noreferrer"><code>LayerContentsRedrawPolicy</code></a>s have been tried, not effective to the problem.</p>
  
  <h2>macOS's Finder</h2>
  
  <p>Finder has a sidebar hiding functionality. The animation is butter smooth. When in the outline mode, the column header has some suspicious transition going on. </p>
  
  <p>Though we can't see how Finder optimized the animation, at least it shows that smooth animation is possible.</p>
  
  <p>Any suggestions or answers will be appreciated.</p>