A decorationview should appear for each section in my flowlayout, which works. But when I scroll down, the decoration view sometimes only appears when row 0 appears. Of course, because of (if decatts.indexPath.row == 1). But if I don't use the If condition, a decorationview appears for each attribute. I don't get it! The goal is -> that a single decorationview appears for each section at the CORRECT rect, just a background behind the section. Without any delays, and not multiple times for a single section
override func layoutAttributesForElements(in rect: CGRect)
-> [UICollectionViewLayoutAttributes]? {
let attributes = super.layoutAttributesForElements(in: rect)!
var allAttributes = [UICollectionViewLayoutAttributes]()
for attribute in attributes {
if let decatts = self.layoutAttributesForDecorationView(ofKind:"background", at:attribute.indexPath) {
if decatts.indexPath.row == 1 {
// decorationView appears when row 1 becomes visible, not what i want
let tmpWidth = self.collectionView!.contentSize.width
let tmpHeight = attribute.frame.size.height * 6
decatts.frame = CGRect.init(x: 0, y: attribute.frame.origin.y - 32, width: tmpWidth, height: tmpHeight+55)
decatts.zIndex = attribute.zIndex - 1
allAttributes.append(decatts)
}
}
}
allAttributes.append(contentsOf: attributes)
return allAttributes
}
what i noticed when i print rect in layoutAttributesForElements(in rect: CGRect) almost every 2nd section the height is double.
section x: (-844.0, 16036.0, 1224.0, 844.0)
section y: (-844.0, 15192.0, 1224.0, 1688.0)
And why is origin.x -844?