在我的情况下,我只有一个小节,该小节有11个项目。问题是我无法将其滚动到最后一个项目。我只能从左到小滚动一个距离。正确的方向,它使我反弹。 这是我的代码:
class RecommendGameView: UIView {
//...
override func layoutSubviews() {
super.layoutSubviews()
let layout = gameCollectionView.collectionViewLayout as! UICollectionViewFlowLayout
layout.itemSize = CGSize(width: 80, height: 90)
gameCollectionView.alwaysBounceHorizontal = true
gameCollectionView.register(UINib(nibName: "CollectionGameCell", bundle: nil), forCellWithReuseIdentifier: kGameCellID)
gameCollectionView.contentInset = UIEdgeInsets(top: 0, left: kEdgeInsetMargin, bottom: 0, right: kEdgeInsetMargin)
}
}
extension RecommendGameView : UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return (groups?.count ?? 0)
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = gameCollectionView.dequeueReusableCell(withReuseIdentifier: kGameCellID, for: indexPath) as! CollectionGameCell
cell.group = groups![indexPath.item]
return cell
}
}