如何聚焦集合视图的可见单元格的最后一个单元格?

时间:2016-09-15 06:12:59

标签: objective-c swift uicollectionview flowlayout

我想聚焦并更改collectionView的可见单元格的最后一个单元格的框架。

我想要像this这样的集合视图行为。

我发现library更改了集合视图的第一个单元格,但我想更改最后一个单元格的框架。该库使用流程布局。

override func prepareLayout() {

cache.removeAll(keepCapacity: false)

let standardHeight = UltravisualLayoutConstants.Cell.standardHeight
let featuredHeight = UltravisualLayoutConstants.Cell.featuredHeight

var frame = CGRectZero
var y: CGFloat = 0

for item in 0..<numberOfItems {
    // 1
    let indexPath = NSIndexPath(forItem: item, inSection: 0)
    let attributes = UICollectionViewLayoutAttributes(forCellWithIndexPath: indexPath)

    // 2
    attributes.zIndex = item
    var height = standardHeight

    // 3
    if indexPath.item == featuredItemIndex
    {
            // 4
            let yOffset = standardHeight * nextItemPercentageOffset
            y = collectionView!.contentOffset.y - yOffset
            height = featuredHeight
    } else if indexPath.item == (featuredItemIndex + 1) && indexPath.item != numberOfItems {
            // 5
            let maxY = y + standardHeight
            height = standardHeight + max((featuredHeight - standardHeight) * nextItemPercentageOffset, 0)
            y = maxY - height
    }

    // 6
    frame = CGRect(x: 0, y: y, width: width, height: height)
    //print("Item : \(item) : \(frame)");
    attributes.frame = frame
    cache.append(attributes)
    y = CGRectGetMaxY(frame)
}

}

library使用上面的函数来更改所有元素的框架。

任何人都可以告诉我如何实现this

1 个答案:

答案 0 :(得分:0)

您可以使用visible cells of a UICollectionView获取可见单元格数组并专注于数组的lastObject

相关问题