Scroll UICollectionView to bottom

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

    Swift 5 & 4 Just Call this Function when you want to display the last cell of collectionview

    //MARK:- Collection view Scroll to End
    func funColvScrollToEnd()
    {
        let item = self.collectionView(self.colv!, numberOfItemsInSection: 0) - 1
        let lastItemIndex = NSIndexPath(item: item, section: 0)
        self.colv?.scrollToItem(at: lastItemIndex as IndexPath, at: .bottom, animated: false)
    }
    //MARK:- You can use .right/ .left/ .top/ .bottom  
    

提交回复
热议问题