@@ -32,7 +32,6 @@ fileprivate func > <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
32
32
}
33
33
}
34
34
35
-
36
35
@objc protocol CHTCollectionViewDelegateWaterfallLayout : UICollectionViewDelegate , UICollectionViewDataSource {
37
36
38
37
func collectionView ( _ collectionView: UICollectionView , layout collectionViewLayout: UICollectionViewLayout ,
@@ -52,9 +51,7 @@ fileprivate func > <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
52
51
}
53
52
54
53
enum CHTCollectionViewWaterfallLayoutItemRenderDirection : NSInteger {
55
- case chtCollectionViewWaterfallLayoutItemRenderDirectionShortestFirst
56
- case chtCollectionViewWaterfallLayoutItemRenderDirectionLeftToRight
57
- case chtCollectionViewWaterfallLayoutItemRenderDirectionRightToLeft
54
+ case shortestFirst, leftToRight, rightToLeft
58
55
}
59
56
60
57
class CHTCollectionViewWaterfallLayout : UICollectionViewLayout {
@@ -90,14 +87,12 @@ class CHTCollectionViewWaterfallLayout : UICollectionViewLayout{
90
87
didSet{
91
88
invalidateLayout ( )
92
89
} }
93
-
94
-
95
- var itemRenderDirection : CHTCollectionViewWaterfallLayoutItemRenderDirection = . chtCollectionViewWaterfallLayoutItemRenderDirectionShortestFirst{
90
+
91
+ var itemRenderDirection : CHTCollectionViewWaterfallLayoutItemRenderDirection = . shortestFirst {
96
92
didSet{
97
93
invalidateLayout ( )
98
94
} }
99
-
100
-
95
+
101
96
// private property and method above.
102
97
weak var delegate : CHTCollectionViewDelegateWaterfallLayout ? {
103
98
get {
@@ -332,7 +327,6 @@ class CHTCollectionViewWaterfallLayout : UICollectionViewLayout{
332
327
*
333
328
* @return index for the longest column
334
329
*/
335
-
336
330
func longestColumnIndex( ) -> NSInteger {
337
331
var index = 0
338
332
var longestHeigth : CGFloat = 0.0
@@ -354,11 +348,11 @@ class CHTCollectionViewWaterfallLayout : UICollectionViewLayout{
354
348
func nextColumnIndexForItem ( _ item : NSInteger ) -> Int {
355
349
var index = 0
356
350
switch ( self . itemRenderDirection) {
357
- case . chtCollectionViewWaterfallLayoutItemRenderDirectionShortestFirst :
351
+ case . shortestFirst :
358
352
index = self . shortestColumnIndex ( )
359
- case . chtCollectionViewWaterfallLayoutItemRenderDirectionLeftToRight :
353
+ case . leftToRight :
360
354
index = ( item% self . columnCount)
361
- case . chtCollectionViewWaterfallLayoutItemRenderDirectionRightToLeft :
355
+ case . rightToLeft :
362
356
index = ( self . columnCount - 1 ) - ( item % self . columnCount) ;
363
357
}
364
358
0 commit comments