title: UICollectionView resize on screen rotation
body: <p>I'm struggling with resizing collection view. </p>
  
  <p>Currently I'm having a flow layout method that counts size:</p>
  
  <pre><code>func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -&gt; CGSize {
          if let cell = collectionView.cellForItem(at: indexPath) {
              let pokemonCell = cell as! PokemonCell
              pokemonCell.setNeedsDisplay()
          }
          return CGSize(width: 150, height: collectionView.bounds.size.height)
      }
  </code></pre>
  
  <p>And also two methods for resizing  on rotation:</p>
  
  <pre><code>override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
      super.viewWillTransition(to: size, with: coordinator)
      guard let flowLayout = self.collectionView.collectionViewLayout as? UICollectionViewFlowLayout else {
          return
      }
      flowLayout.invalidateLayout()
      self.collectionView.reloadData()
  }
  
  override func viewWillLayoutSubviews() {
      super.viewWillLayoutSubviews()
  
      collectionView.frame = self.view.bounds
      self.collectionView.reloadData()
  
  }
  </code></pre>
  
  <p>Cell content is centered in container. When I change layout, cell content starts jumping. Some of them reposition themselves, some remain on <strong>y</strong> position of previous layout. Sometimes content gets correct positionig and than goes back wile scrolling.</p>
  
  <p><a href="https://i.stack.imgur.com/x9LJ1.png" rel="nofollow noreferrer">screenshot</a></p>