Scroll UICollectionView to bottom

前端 未结 13 1166
梦毁少年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 13:02

    Swift 4:

    For Horizontal Scrolling - .right

    For Vertical Scrolling - .bottom

    let lastItemIndex = self.collectionView.numberOfItems(inSection: 0) - 1
    let indexPath:IndexPath = IndexPath(item: lastItemIndex, section: 0)
    self.collectionView.scrollToItem(at: indexPath, at: .right, animated: false)
    

提交回复
热议问题