【发布时间】:2017-10-19 12:29:23
【问题描述】:
从上图中,我有 UICollectionView 和 4 个自定义单元格。任何时候屏幕上都可以显示 2 或 3 个单元格。如何判断“单元格 1”或“单元格 2”何时 100% 显示在屏幕上?
两个
collectionView.visibleCells
collectionView.indexPathsForVisibleItems
返回数组并且不告诉你屏幕上的单元格是否 100%。
在图片的情况下,didSelectItemAt上会显示以下内容
collectionView.visibleCells
[<Shot_On_Goal.MainCollectionViewCell: 0x101f525c0; baseClass = UICollectionViewCell; frame = (190 7.66667; 454 350); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x1c0237300>>, <Shot_On_Goal.HeaderCollectionViewCell: 0x101f4d580; baseClass = UICollectionViewCell; frame = (10 0; 170 365); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x1c0236800>>, <Shot_On_Goal.TheirHockeyNetCollectionViewCell: 0x101f55520; baseClass = UICollectionViewCell; frame = (654 7.66667; 454 350); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x1c0238fe0>>]
collectionView.indexPathsForVisibleItems
[[0, 1], [0, 0], [0, 2]]
【问题讨论】:
-
您考虑过使用CGRectContainsRect 吗?
-
看起来有人已经用tableViewCell 做到了这一点。
标签: ios swift uicollectionview uicollectionviewcell