我有一個collectionView,並且它的scrollview有一個擴展名,它可以幫助我像這樣獲得我的單元格20像素(來自下一個單元格的最小空間)右側:每次滾動視圖結束時居中顯示一個collectionView的單元格
我的分機是這樣的:(如果我可以與任何其他的方式做到隨時告訴它)
extension MyProject : UIScrollViewDelegate
{
func scrollViewWillEndDragging(scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>)
{
let layout = self.collectionView?.collectionViewLayout as! UICollectionViewFlowLayout
let cellWidthIncludingSpacing = layout.itemSize.width + layout.minimumLineSpacing
var offset = targetContentOffset.memory
let index = (offset.x + scrollView.contentInset.left)/cellWidthIncludingSpacing
let roundedIndex = round(index)
offset = CGPoint(x: roundedIndex * cellWidthIncludingSpacing - scrollView.contentInset.left, y: -scrollView.contentInset.top)
targetContentOffset.memory = offset
}
}
是否啓用了的CollectionView滾動分頁考慮contentInset? –
@BharatModi沒有任何變化 –