title: How to invalidate layout of a uicollectionview within the uicollectionviewcell of a parent uicollectionview?
body: <p>Here's the <a href="https://i.stack.imgur.com/YRbYW.jpg" rel="nofollow noreferrer">layout</a> I have.</p>
  
  <p>I have a UICollectionView that has UICollectionViews embedded in its cells. On the iPad, when I rotate the screen, I can invalidate the layout of the parent UICollectionView by overriding </p>
  
  <pre><code>func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator)
  </code></pre>
  
  <p>This works just fine. However, I am not sure how to redirect this trigger to the UICollectionViews inside the individual cells.</p>
  
  <p>So far, I have tried to invalidate the layout of those UICollectionViews thru <code>func layoutSubviews()</code>. This is not very consistent as some cells are still with old layout. However, this:</p>
  
  <pre><code>func willTransition(from oldLayout: UICollectionViewLayout, to newLayout: UICollectionViewLayout)
  </code></pre>
  
  <p>doesn't get triggered at all for this scenario.</p>
  
  <p>I have also tried <code>func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -&gt; Bool</code> in the flow layout for the embedded UICollectionViews.</p>
  
  <p>I'm not using self-sizing cells, i.e., I'm providing the size of the cells through</p>
  
  <pre><code>func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -&gt; CGSize
  </code></pre>
  
  <p>What's the cleanest way to solve this to have consistent results?</p>
  
  <p>Appreciate any pointers in this regard.</p>