UICollectionView automatically scroll to bottom when screen loads

后端 未结 9 2053
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:55

    none of these were working so well for me, I ended up with this which will work on any scroll view

    extension UIScrollView {
        func scrollToBottom(animated: Bool) {
            let y = contentSize.height - 1
            let rect = CGRect(x: 0, y: y + safeAreaInsets.bottom, width: 1, height: 1)
            scrollRectToVisible(rect, animated: animated)
        }
    }
    

提交回复
热议问题