Scroll UICollectionView to bottom

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

    For Swift -

    For Horizontal Scrolling - .right

    For Vertical Scrolling - .bottom

    override func viewDidLayoutSubviews() {
            let section = 0
            let lastItemIndex = self.dateCollectionView.numberOfItemsInSection(section) - 1
            let indexPath:NSIndexPath = NSIndexPath.init(forItem: lastItemIndex, inSection: section)
            self.dateCollectionView.scrollToItemAtIndexPath(indexPath, atScrollPosition: .right, animated: false)
        }
    

提交回复
热议问题