Scroll UICollectionView to bottom

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

    For Swift 3 and multiple sections

    /**
    
     This method scrolls the *UICollectionView* to the last item in the last section
    
     */
    
    func scrollToLastItem() {
    
        let lastSection = collectionView.numberOfSections - 1
    
        let lastRow = collectionView.numberOfItems(inSection: lastSection)
    
        let indexPath = IndexPath(row: lastRow - 1, section: lastSection)
    
        self.collectionView.scrollToItem(at: indexPath, at: .right, animated: true)
    
    }
    

提交回复
热议问题