title: iOS 10/11 UICollectionViewFlowLayout using UICollectionViewFlowLayoutAutomaticSize results in footer supplementary view misaligned
body: <p>So this is an interesting issue we found with <code>UICollectionViewFlowLayout</code> on iOS 10 (still an issue on 11) and using <code>UICollectionViewFlowLayoutAutomaticSize</code> for the estimatedItemSize.</p>
  
  <p>We've found that using <code>UICollectionViewFlowLayoutAutomaticSize</code> for the estimatedItemSize results in the footer supplementary view floating above the bottom few cells.(Red/Pink is the header, Green is the footer.)</p>
  
  <p><a href="https://i.stack.imgur.com/pPLK4.png" rel="noreferrer"><img src="https://i.stack.imgur.com/pPLK4.png" alt="UICollectionViewFlowLayoutAutomaticSize problem"></a>
  <a href="https://i.stack.imgur.com/0fAt7.png" rel="noreferrer"><img src="https://i.stack.imgur.com/0fAt7.png" alt="enter image description here"></a></p>
  
  <p><strong>Here is the VC code of a sample app:</strong></p>
  
  <pre><code>import UIKit
  
  class ViewController: UIViewController {
  
      // MARK: Properties
  
      let texts: [String] = [
          "This is some text",
          "This is some more text",
          "This is even more text"
      ]
  
      // MARK: Outlets
  
      @IBOutlet var collectionView: UICollectionView! {
          didSet {
              self.collectionView.backgroundColor = .orange
          }
      }
  
      // MARK: Lifecycle
  
      override func viewDidLoad() {
  
          super.viewDidLoad()
  
          // Layout
          let layout = UICollectionViewFlowLayout()
          layout.scrollDirection = .vertical
          if #available(iOS 10.0, *) {
              layout.estimatedItemSize = UICollectionViewFlowLayoutAutomaticSize
          } else {
              layout.estimatedItemSize = CGSize(width: self.collectionView.bounds.width, height: 50)
          }
          self.collectionView.collectionViewLayout = layout
  
          // Register Cells
          self.collectionView.register(UINib(nibName: "TextCell", bundle: nil), forCellWithReuseIdentifier: String(describing: TextCell.self))
          self.collectionView.register(UINib(nibName: "SectionHeader", bundle: nil), forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: String(describing: SectionHeader.self))
          self.collectionView.register(UINib(nibName: "SectionFooter", bundle: nil), forSupplementaryViewOfKind: UICollectionElementKindSectionFooter, withReuseIdentifier: String(describing: SectionFooter.self))
  
          self.collectionView.reloadData()
      }
  }
  
  // MARK: - UICollectionViewDelegateFlowLayout Methods
  
  extension ViewController: UICollectionViewDelegateFlowLayout {
  
      func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -&gt; CGSize {
  
          return CGSize(width: self.collectionView.bounds.width, height: 90)
      }
  
      func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -&gt; CGSize {
  
          return CGSize(width: self.collectionView.bounds.width, height: 90)
      }
  }
  
  // MARK: - UICollectionViewDataSource Methods
  
  extension ViewController: UICollectionViewDataSource {
  
      public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
  
          return self.texts.count
      }
  
      func numberOfSections(in collectionView: UICollectionView) -&gt; Int {
          return 1
      }
  
      public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
  
          let cell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: TextCell.self), for: indexPath)
  
          if let textCell = cell as? TextCell {
  
              let text = self.texts[indexPath.row]
              textCell.configure(text: text)
          }
  
          return cell
      }
  
      func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -&gt; UICollectionReusableView {
  
          switch kind {
          case UICollectionElementKindSectionHeader:
  
              return collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: String(describing: SectionHeader.self), for: indexPath)
  
          case UICollectionElementKindSectionFooter:
  
              return collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: String(describing: SectionFooter.self), for: indexPath)
  
          default:
              return UICollectionReusableView()
          }
      }
  }
  
  // MARK: - UICollectionViewDelegate Methods
  
  extension ViewController: UICollectionViewDelegate {
  
  }
  </code></pre>
  
  <p>Has anyone managed to get UICollectionViewFlowLayoutAutomaticSize to work on iOS 10 with supplementary header and footer views? If I add a size to the estimatedItemSize then it appears to work, but I want to know if there is a bug in using the new iOS 10 feature or if I'm using it incorrectly.</p>
  
  <p>The bug filed with Apple has the ID: <strong>28843116</strong></p>
  
  <p><strong>UPDATE</strong>: This still appears to be an issue on 10.3 Beta 1</p>
  
  <p><strong>UPDATE 2</strong>: This still appears to be an issue in iOS 11 Beta 1</p>