我想聚焦并改变collectionView的可见单元格的最后一个单元格的框架。
我希望集合视图的行为像这样。
我找到了改变集合视图的第一个单元格的库,但我想改变最后一个单元格的框架。这个库使用流布局。
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)
}
}
标准库使用上述函数更改所有元素的框架。
谁能告诉我怎样才能做到这一点?
您可以使用UICollectionView的可见单元格来获取可见单元格数组,并关注该数组的lastObject