Scroll UICollectionView to bottom

前端 未结 13 1052
梦毁少年i
梦毁少年i 2021-02-02 12:05

I would like to scroll the UICollectionView to the bottom so the last item is in the view. I have tried to use scrollToItemAtIndexPath but it does not seem to be working. I want

13条回答
  •  渐次进展
    2021-02-02 12:43

    Updated for Swift 3:

    let item = self.collectionView(self.collectionView!, numberOfItemsInSection: 0) - 1
    let lastItemIndex = IndexPath(item: item, section: 0)
    collectionView?.scrollToItem(at: lastItemIndex, at: UICollectionViewScrollPosition.top, animated: true)
    

提交回复
热议问题