title: Animating a navigation bar color
body: <p>I am trying to animate a change of color of a navigation bar when popping back to a previous controller. To give it some context, I have controller A which is a collectionView Controller and has an opaque navigation bar color set by:</p>
  
  <pre><code>self.navigationController?.navigationBar.barTintColor = UIColor.rgb(red: 244, green: 67, blue: 54)
  self.navigationController?.navigationBar.tintColor = .white
  self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName : UIColor.white]
  self.navigationController?.navigationBar.isTranslucent = false
  </code></pre>
  
  <p>Once a collectionViewCell is selected I push to the next controller, B, where the navigation bar is altered to become transparent:</p>
  
  <pre><code>self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
  self.navigationController?.navigationBar.shadowImage = UIImage()
  self.navigationController?.navigationBar.isTranslucent = true
  </code></pre>
  
  <p>When a user taps on the back arrow, I want the navigationBar to return to it's original colors. I have tried a simple UIView animation on the controller B's <code>viewWillDissappear</code> function, <code>willMove(toParentViewController)</code> and the <code>viewWillAppear</code> function on Controller A:</p>
  
  <p>Here is the animation:</p>
  
  <pre><code>UIView.animate(withDuration: 0.5) {
     self.navigationController?.navigationBar.barTintColor = UIColor.rgb(red: 244, green: 67, blue: 54)
     self.navigationController?.navigationBar.setBackgroundImage(nil, for: .default)
     self.navigationController?.navigationBar.shadowImage = nil
     self.navigationController?.navigationBar.isTranslucent = false
     self.navigationController?.navigationBar.layoutIfNeeded()
  }
  </code></pre>
  
  <p>After doing this I tried using a transition coordinator but got the same results:</p>
  
  <pre><code>guard let coordinator = self.transitionCoordinator else {
          return
      }
  
  coordinator.animate(alongsideTransition: {
      [weak self] context in
     self?.navigationController?.navigationBar.barTintColor = UIColor.rgb(red: 244, green: 67, blue: 54)
     self?.navigationController?.navigationBar.setBackgroundImage(nil, for: .default)
     self?.navigationController?.navigationBar.shadowImage = nil
     self?.navigationController?.navigationBar.isTranslucent = false
     self?.navigationController?.navigationBar.layoutIfNeeded()
  }, completion: nil)
  </code></pre>
  
  <p>It seems that no matter what I try, or where I put the code I always end up with the same outcome. I am aware that the code is repetitive, but I was just trying to figure out why, so a lot of copying and pasting occurred.</p>
  
  <p><a href="https://i.stack.imgur.com/5XMJv.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5XMJv.gif" alt="Nav Bar result"></a></p>
  
  <p>From what I can tell, I think that it has something to do with the background view of the previous controller, but I am stumped, I seem to see a black screen before the animation under the navigation bar. Any help would be greatly appreciated.</p>
  
  <p>Thanks</p>