How to tell if a UICollectionViewCell is 100% displayed

extension SavedDrawingViewController: UICollectionViewDataSource {
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 1
    }
   
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return drawings.collection.count
    }
   

    func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
            let newcell = cell as! SavedImageCell
            newcell.setData(drawing: drawings.collection[indexPath.row])
            newcell.deselect()
            self.collectionView.deselectItem(at: indexPath, animated: false)
            newcell.setSelection(selectionMode)

    }
   
  
   
   
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
       

       
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: sellId, for: indexPath) as! SavedImageCell
       

            cell.invisible()
            cell.deselect()
            self.collectionView.deselectItem(at: indexPath, animated: false)
            cell.setSelection(selectionMode)
       
       

        return cell
    }
}


HEre is my attempt..... line #11 was supposed to set the "visible" cells to the image and line #23 was to set the "placeholders." The functionality im going for here is to have the cells with a placeholder imageView until they are 100% in view. I can't quite accomplish this with the code I presented. Any ideas?

Replies

I would do this with some computation, taking into account:

- collection view frame size

- scroll position, from scrollView.contentOffset.y

    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        print("Scroll Offset", scrollView.contentOffset.y)
    }


- height of cells

- Vertical intercells value


You could also:

- for each visible cell

- find its position and xheck if it is beyond scroll view limit.


Note: take care, with Retina displays, you may count pixels, not points

Claude31 I appreciate that you led me in the right direction, I have a few questions... I think i will find each cell position and check if is beyond the scroll limit. But I don't know where to begin on such a matter? Where do I find the contentOffset of each cell?