Commit c39844a521baea6ba7a827953dc0da64618915dd

Authored by yanglingyu
1 parent efe59af2

修复瀑布流卡顿问题

CNLiveVideoClassifyKit/Classes/SearchView/View/CNCollectionViewLayout.m
@@ -10,6 +10,7 @@ @@ -10,6 +10,7 @@
10 @interface CNCollectionViewLayout () 10 @interface CNCollectionViewLayout ()
11 11
12 @property (nonatomic, strong)NSMutableDictionary *maxDic;//储存列的长度 12 @property (nonatomic, strong)NSMutableDictionary *maxDic;//储存列的长度
  13 +@property (nonatomic, strong)NSMutableArray *attArray;
13 14
14 @end 15 @end
15 16
@@ -23,6 +24,18 @@ @@ -23,6 +24,18 @@
23 } 24 }
24 - (void)prepareLayout{ 25 - (void)prepareLayout{
25 [super prepareLayout]; 26 [super prepareLayout];
  27 + for (int i = 0; i < self.colCount; i ++) {
  28 + NSString *key = [NSString stringWithFormat:@"%d",i];
  29 + self.maxDic[key] = @0;
  30 + }
  31 + self.attArray = [[NSMutableArray alloc] init];
  32 + int count = (int)[self.collectionView numberOfItemsInSection:0];
  33 +
  34 + for (int i = 0 ; i < count ; i ++) {
  35 + UICollectionViewLayoutAttributes *att = [self layoutAttributesForItemAtIndexPath:[NSIndexPath indexPathForItem:i inSection:0]];
  36 + [self.attArray addObject:att];
  37 + }
  38 +
26 } 39 }
27 /** 40 /**
28 * 决定collectionview能滑动的范围 41 * 决定collectionview能滑动的范围
@@ -42,20 +55,7 @@ @@ -42,20 +55,7 @@
42 * 布局layout 55 * 布局layout
43 */ 56 */
44 - (nullable NSArray<__kindof UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect{ 57 - (nullable NSArray<__kindof UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect{
45 - for (int i = 0; i < self.colCount; i ++) {  
46 - NSString *key = [NSString stringWithFormat:@"%d",i];  
47 - self.maxDic[key] = @0;  
48 - }  
49 -  
50 - NSMutableArray *arr = [NSMutableArray array];  
51 - int count = (int)[self.collectionView numberOfItemsInSection:0];  
52 -  
53 - for (int i = 0 ; i < count ; i ++) {  
54 - UICollectionViewLayoutAttributes *att = [self layoutAttributesForItemAtIndexPath:[NSIndexPath indexPathForItem:i inSection:0]];  
55 - [arr addObject:att];  
56 - }  
57 -  
58 - return arr; 58 + return self.attArray;
59 } 59 }
60 /** 60 /**
61 决定了每个item的位置,大小 61 决定了每个item的位置,大小