[英]How to Focus last cell of visible cell of collection view?
I want to focus and change the frame of last cell of visible cell of collectionView. 我想聚焦并更改collectionView的可见单元格的最后一个单元格的框架。
I want collection view behaviour like this . 我想要像这样的集合视图行为。
I found the library that change the first cell of collection view but I want to change the frame of last cell. 我找到了更改集合视图的第一个单元格的库 ,但我想更改最后一个单元格的框架。 This library using flow layout.
此库使用流布局。
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 uses above function to change the frame of all elements. 库使用上面的函数来改变所有元素的框架。
Can any one tell me that how can I achieve this . 任何人都可以告诉我,我怎样才能做到这一点 。
您可以使用UICollectionView的可见单元格来获取可见单元格数组,并将焦点放在数组的lastObject上
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.