próbować używać go przez Sub-classing UICollectionViewFlowLayout
let flowLayout = LeftAgignedFlowLayout()
flowLayout.minimumLineSpacing = 18
flowLayout.minimumInteritemSpacing = 8
flowLayout.scrollDirection = .vertical
self.collectionViewLayout = flowLayout
class LeftAgignedFlowLayout : UICollectionViewFlowLayout {
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
let arr = super.layoutAttributesForElements(in: rect)!
return arr.map {
atts in
var atts = atts
if atts.representedElementCategory == .cell {
let ip = atts.indexPath
atts = self.layoutAttributesForItem(at:ip)!
}
return atts
}
}
override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
var atts = super.layoutAttributesForItem(at:indexPath)!
if indexPath.item == 0 {
return atts
}
if atts.frame.origin.x - 1 <= self.sectionInset.left {
return atts
}
let ipPv = IndexPath(item:indexPath.row-1, section:indexPath.section)
let fPv = self.layoutAttributesForItem(at:ipPv)!.frame
let rightPv = fPv.origin.x + fPv.size.width + self.minimumInteritemSpacing
atts = atts.copy() as! UICollectionViewLayoutAttributes
atts.frame.origin.x = rightPv
return atts
}
}
Wiem, że to bardzo trywialne pytanie, ale śmiem prosić go. Czy przypisałeś własną klasę do układu swojej kolekcjiZobacz poprawnie? – Adeel
Dzięki za pytanie :-) Jeśli masz czas, spójrz na to Playground: https://github.com/JCzz/CollectionView Ogólnie próbuję tylko skalować Widok na środku ekranu. –
@ ChrisG. Mam ten sam problem. Wszystko wydaje się w porządku, z wyjątkiem "LayoutAttributesForItem" nie uruchamia się wcale. Nie jestem pewien dlaczego. – jnel899