How to scroll to the bottom of a section with IGListKit

Viewed 1560

I'm trying to scroll to the bottom of a UICollectionView implemented with IGListKit. My method to do so:

func scrollToBottom(animated: Bool = true) {
    if let last = self.adapter.objects().last {
        self.adapter.scroll(
            to: last,
            supplementaryKinds: nil,
            scrollDirection: UICollectionViewScrollDirection.vertical,
            scrollPosition: UICollectionViewScrollPosition.bottom,
            animated: animated)
    }
}

This does scroll to the last item, however, it did not scroll to the bottom of the last object.

The actual result:

The actual result

The desired result:

The desired result

Any suggestions how to get my desired result?

2 Answers

Or, you can use UICollectionViewScrollPosition.top instead UICollectionViewScrollPosition.bottom and scroll to bottom works normally. And updated to Swift 4.x

self.adapter.scroll(
  to: self.<#arrayOfObjects#>.last, 
  supplementaryKinds: nil, 
  scrollDirection: .vertical, 
  scrollPosition: .top
  animated: true)

Solved it by using the underlying UICollectionView and the setContentOffset method

func scrollToBottom(animated: Bool = true) {
    let bottomOffset = CGPoint(
        x: 0,
        y: self.collectionView.contentSize.height
            - self.collectionView.bounds.size.height
            + self.collectionView.contentInset.bottom)
    self.collectionView.setContentOffset(bottomOffset, animated: animated)
}
Related