How to determine when a custom UICollectionViewCell is 100% on the screen

前端 未结 3 586
我在风中等你
我在风中等你 2020-12-29 08:21

From the diagram above I have UICollectionView with 4 custom cells. At any time 2 or three cells can be on the screen. How can I tell when \"cell 1\"

3条回答
  •  悲&欢浪女
    2020-12-29 08:55

    Here's an extension for it, based don DonMag's answer:

    extension UICollectionView {
        var fullyVisibleCells : [UICollectionViewCell] {
            return self.visibleCells.filter { cell in
                let cellRect = self.convert(cell.frame, to: self.superview)
                return self.frame.contains(cellRect) }
        }
    }
    

提交回复
热议问题