【发布时间】:2017-08-02 08:34:29
【问题描述】:
我已尝试使用以下代码从 collectionview 中找出最后一个可见索引路径,但可见单元格不断变化,我无法找到最后一个可见项目。
for cell: UICollectionViewCell in collView.visibleCells {
// indexPath = collView.indexPathForCell(cell)!
var visibleRect = CGRect()
visibleRect.origin = collView.contentOffset
visibleRect.size = collView.bounds.size
let visiblePoint = CGPoint(x: visibleRect.width, y: visibleRect.height)
if let indexPath = collView.indexPathForItem(at: visiblePoint) //If let is
{
return indexPath
} else {
return IndexPath(row: NSNotFound, section: 0)
}
}
输出
"<NSIndexPath: 0x17422c680> {length = 2, path = 0 - 4}",
"<NSIndexPath: 0x17403e0c0> {length = 2, path = 0 - 6}",
"<NSIndexPath: 0x1742261c0> {length = 2, path = 0 - 10}",
"<NSIndexPath: 0x17422adc0> {length = 2, path = 0 - 1}",
"<NSIndexPath: 0x1742205e0> {length = 2, path = 0 - 3}",
"<NSIndexPath: 0x17422a1a0> {length = 2, path = 0 - 7}",
"<NSIndexPath: 0x174227080> {length = 2, path = 0 - 9}",
"<NSIndexPath: 0x174229b40> {length = 2, path = 0 - 0}"
【问题讨论】:
-
你能展示一下你的收藏视图是什么样子的吗?
-
同照片应用
标签: uicollectionview cell nsindexpath