UICollectionView automatically scroll to bottom when screen loads

后端 未结 9 2093
Happy的楠姐
Happy的楠姐 2021-02-05 02:44

I\'m trying to figure out how to scroll all the way to the bottom of a UICollectionView when the screen first loads. I\'m able to scroll to the bottom when the status bar is tou

9条回答
  •  遥遥无期
    2021-02-05 03:03

    Consider if you can use performBatchUpdates like this:

    private func reloadAndScrollToItem(at index: Int, animated: Bool) {
        collectionView.reloadData()
        collectionView.performBatchUpdates({
            self.collectionView.scrollToItem(at: IndexPath(item: index, section: 0),
                                             at: .bottom,
                                             animated: animated)
        }, completion: nil)
    }
    

    If index is the index of the last item in the collection's view data source it'll scroll all the way to the bottom.

提交回复
热议问题