0
我試圖讓電池的indexpath中的CollectionView像這樣使用擴展掙扎在的CollectionView
extension InfiniteCollectionView
{
var centerPoint : CGPoint {
get {
return CGPoint(x: self.contentOffset.x + (CGRectGetWidth(self.bounds) * 0.5) , y: self.contentOffset.y + (CGRectGetWidth(self.bounds) * 0.5))
}
}
var centerCellIndexPath: NSIndexPath?{
return self.indexPathForItemAtPoint(self.centerPoint)
}
}
擴展
碼中心拿到細胞指數路徑這樣我就可以在中心indexpath像這樣
print(collectionVw.centerCellIndexPath)
但這種不斷返回nil我似乎無法找出原因,這值得注意的是該擴展名爲InfiniteCollectionView,它被設置爲collectionview中的自定義類而不是視圖控制器。