title: How to set position of cell of collectionview swift?
body: <p>i am using collectionview  to show image in full screen and allowing scrolling between different images. but when orientation will change it's not showing properly.<a href="https://i.stack.imgur.com/0iyHf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0iyHf.png" alt="Here image of screen after orientation change"></a>.And this is my code</p>
  
  <pre><code>override func willRotate(to toInterfaceOrientation: UIInterfaceOrientation, duration: TimeInterval) {
  
  
  //    collectionView.reloadData()
      collectionView.collectionViewLayout.invalidateLayout()
      if visibleCell != nil {
  
       collectionView.selectItem(at: visibleCell as IndexPath?, animated: true, scrollPosition: .centeredHorizontally)
  
       }
  }
  
  
  func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
      return images.count
  }
  
  func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
  
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ImageCell", for: indexPath) as! ImageCollectionViewCell
          print(cell.frame)
        cell.SectionImage.image = images[indexPath.row].image
  
        return cell
  }
  
  func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -&gt; CGSize {
  
      return CGSize(width: self.view.frame.width, height: self.view.frame.height)
  
  }
  
  func numberOfSections(in collectionView: UICollectionView) -&gt; Int {
      return 1
  }
  
  func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -&gt; CGFloat {
      return 0
  }
  func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -&gt; CGFloat {
      return 0
  }
  </code></pre>