0
我有一个水平集合视图。基本上,第一个显示的项目是“活动”项目。并将卡扣划过每个物品。UICollectionView捕捉到0,0 - 滚动过去界限
我遇到的问题是我需要能够滚动最后一个项目以捕捉所有的方式到前面。目前拖到最后时,它不再捕捉到第一个单元。
对不起,如果我没有任何意义。基本上,每个单元格的最左边的框架应该捕捉到collectionView的0,0。目前,它对于前两个单元完全适用。但在此之后,它碰到了边界并且不允许它捕捉。我希望能够拖动和最后单元格捕捉到0,0
谢谢!
看到这里的问题:
这里是我的布局子类:
class UserFlowLayout: UICollectionViewFlowLayout {
required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) }
override init() {
super.init()
scrollDirection = .horizontal
itemSize = CGSize(width: 70, height: 90)
minimumInteritemSpacing = 15.0
minimumLineSpacing = 15.0
}
override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint, withScrollingVelocity velocity: CGPoint) -> CGPoint {
guard let collectionView = collectionView else { return super.targetContentOffset(forProposedContentOffset: proposedContentOffset, withScrollingVelocity: velocity) }
var offsetAdjustment = CGFloat.greatestFiniteMagnitude
let horizontalOffset = proposedContentOffset.x + collectionView.contentInset.left
let targetRect = CGRect(x: proposedContentOffset.x, y: 0, width: collectionView.bounds.size.width, height: collectionView.bounds.size.height)
let layoutAttributesArray = super.layoutAttributesForElements(in: targetRect)
layoutAttributesArray?.forEach({ (layoutAttributes) in
let itemOffset = layoutAttributes.frame.origin.x
if fabsf(Float(itemOffset - horizontalOffset)) < fabsf(Float(offsetAdjustment)) {
offsetAdjustment = itemOffset - horizontalOffset
}
})
return CGPoint(x: proposedContentOffset.x + offsetAdjustment, y: proposedContentOffset.y)
}
}