-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomLayout.swift
More file actions
50 lines (40 loc) · 1.68 KB
/
CustomLayout.swift
File metadata and controls
50 lines (40 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// CustomLayout.swift
// CollectionSwiftBigHeaderDemo
//
// Created by john on 16/5/11.
// Copyright © 2016年 jhon. All rights reserved.
//
import UIKit
class CustomLayout: UICollectionViewFlowLayout {
override func shouldInvalidateLayoutForBoundsChange(newBounds: CGRect) -> Bool {
return true
}
override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
let collectView = self.collectionView
let offset = collectView?.contentOffset
let attributes = super.layoutAttributesForElementsInRect(rect)
if offset!.y < 0 {
let delY = fabs((offset?.y)!)
for layoutAttr in attributes! {
let kind = layoutAttr.representedElementKind
if kind == UICollectionElementKindSectionHeader {
let headerSize = self.headerReferenceSize
var rect = layoutAttr.frame
rect.size.height = headerSize.height + delY
rect.size.width = headerSize.width + delY
rect.origin.x = rect.origin.x - delY/2
rect.origin.y = rect.origin.y - delY
layoutAttr.frame = rect
break
}
}
}
return attributes;
}
// override func layoutAttributesForSupplementaryViewOfKind(elementKind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? {
// let attribute = collectionView?.layoutAttributesForSupplementaryElementOfKind("kind", atIndexPath: indexPath)
//
// return attribute
// }
}