title: How to adjust UICollectionView contentOffset after rotation?
body: <p>I have a <code>UICollectionView</code> with paging enabled, the page <code>contentOffset</code> is not correctly adjusted after rotation.</p>
  
  <p>I overrided the two following methods </p>
  
  <pre><code>override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
  
  collectionView.collectionViewLayout.invalidateLayout()
  }
  
  override func didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation) {
  
  let width = collectionView.bounds.width
  
  var frame = collectionView.frame
  frame.origin.x = width * CGFloat(pageControl.currentPage)
  frame.origin.y = 0
  
  collectionView.scrollRectToVisible(frame, animated: false)
  }
  </code></pre>
  
  <p>but still have the same problem.</p>
  
  <p>What needs to be done for these changes to adjust contentOffset of the current page correctly when the device is rotated?</p>
  
  <p>on landscape the page is positioned correctly , but when the device is rotated to portrait  the page position is incorrect as in the following images</p>
  
  <p><a href="https://i.stack.imgur.com/OOyDC.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OOyDC.jpg" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/4JeZm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4JeZm.png" alt="enter image description here"></a></p>