UICollectionView automatically scroll to bottom when screen loads

后端 未结 9 2091
Happy的楠姐
Happy的楠姐 2021-02-05 02:44

I\'m trying to figure out how to scroll all the way to the bottom of a UICollectionView when the screen first loads. I\'m able to scroll to the bottom when the status bar is tou

9条回答
  •  我在风中等你
    2021-02-05 02:54

    Swift 3 example

    let sectionNumber = 0
    self.collectionView?.scrollToItem(at: //scroll collection view to indexpath
                                      NSIndexPath.init(row:(self.collectionView?.numberOfItems(inSection: sectionNumber))!-1, //get last item of self collectionview (number of items -1)
                                                       section: sectionNumber) as IndexPath //scroll to bottom of current section
                                    , at: UICollectionViewScrollPosition.bottom, //right, left, top, bottom, centeredHorizontally, centeredVertically
                                    animated: true)
    

提交回复
热议问题