class DCLayout: UICollectionViewFlowLayout {
override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool {
return true
}
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
let offset = collectionView!.contentOffset
let attributes = super.layoutAttributesForElements(in: rect)
if offset.y<0 {
let deltaY = fabs(offset.y)
for attrs in attributes! {
let kind = attrs.representedElementKind
if kind == UICollectionElementKindSectionHeader {
let headerSize = self.headerReferenceSize
var headRect = attrs.frame
headRect.size.height = headerSize.height + deltaY
headRect.size.width = headerSize.width + deltaY
headRect.origin.y = headRect.origin.y - deltaY
headRect.origin.x = headRect.origin.x - deltaY / 2
print( headRect.origin.y)
attrs.frame = headRect
}
}
}
return attributes
}
}