Check whether cell at indexPath is visible on screen UICollectionView

后端 未结 4 852
春和景丽
春和景丽 2021-02-19 18:44

I have a CollectionView which displays images to the user. I download these in the background, and when the download is complete I call the following func to update

4条回答
  •  梦如初夏
    2021-02-19 19:35

    Nested UICollectionViews need oft to not scroll at all, so that no contentOffset is ever provided and thus iOS understands all cells as being always visible. In that case it is possible to take the screen boundaries as reference:

        let cellRect = cell.contentView.convert(cell.contentView.bounds, to: UIScreen.main.coordinateSpace)
        if UIScreen.main.bounds.intersects(cellRect) {
            print("cell is visible")
        }
    

提交回复
热议问题