Scroll UICollectionView to bottom

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

    Update for Swift 3

    func viewScrollButton() {
        let lastItem = collectionView(self.collectionView!, numberOfRowsInSection: 0) - 1
        let indexPath: NSIndexPath = NSIndexPath.init(item: lastItem, section: 0)
        self.collectionView.scrollToRow(at: indexPath as IndexPath, at: .bottom, animated: false)
    }
    

提交回复
热议问题