title: Stop Single UICollectionView cell Flowing to the centre of the screen
body: <p>I am trying to understand why Collection View keeps centre aligning just the last cell in a collection.<br>
   I have created a simple Flow layout based collection view. I am using the Autolayout flag - which I am not sure is causing this issue.</p>
  
  <p>Whenever I remove a cell from the Collection view - the first few seem to work fine and roll to the left. However when I remove the second last one, then suddenly the last cell changes from being left aligned to being centre aligned. 
  Does anyone have an explanation? It seems strange.</p>
  
  <p>How do I make it so that all the cells will roll to the left and stay aligned to the left.  </p>
  
  <p>Edit: here is the view hierachy debugging: 
  <a href="https://imgur.com/a/NxidO" rel="noreferrer">http://imgur.com/a/NxidO</a></p>
  
  <p>Here is the view Behaviour </p>
  
  <p><a href="https://i.stack.imgur.com/bledY.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/bledY.gif" alt="Collectionview centring"></a></p>
  
  <p>I have made a simple github to demo it: <a href="https://github.com/grantkemp/CollectionViewIssue" rel="noreferrer">https://github.com/grantkemp/CollectionViewIssue</a></p>
  
  <p>and here is the code:</p>
  
  <pre><code>        var dataforCV = ["short","longer phrase", "Super long Phrase"]
  
  override func viewDidLoad() {
          super.viewDidLoad()
          demoCollectionView.reloadData()
      let layout = UICollectionViewFlowLayout()
  
      // Bug Description  - &gt; UICollectionViewFlowLayoutAutomaticSize will center Align the layout if it has only a single cell - but it will left align the content if there is more than one cell.
  
      // I would expect this behaviour to be consistently left aligning the content.
  
      //How to repeat: If you comment out UICollection​View​Flow​Layout​Automatic​Size then the collection view will show 3 cells being left aligned and it will continue to left align all the content no matter how many cells you remove.
  
      // But: if you leave turn UICollection​View​Flow​Layout​Automatic​Size on - then it will intially show 3 cells being left aligned, and then as you click to remove each cell they will stay left aligned until the last single cell will suddenly center align in the collection view
  
      //  see here for the screen recording:https://i.stack.imgur.com/bledY.gif
      //  see here for the view hierachy debuggins screen: http://imgur.com/a/NxidO
  
      layout.estimatedItemSize = UICollectionViewFlowLayoutAutomaticSize
  
  
      // &lt;-- End Bug Description
      demoCollectionView.collectionViewLayout = layout
  }
  
      //MARk: CollectionView
  
      func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
          let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as? collectionCell
          cell?.text.text  = dataforCV[indexPath.row]
  
          return cell!
  
      }
  
      func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
          return dataforCV.count
      }
      //Remove the item from the array if selected
      func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
          dataforCV.remove(at: indexPath.row)
          demoCollectionView.deleteItems(at: [indexPath])
      }
  </code></pre>