Row-based waterfall view

Row-based waterfall view

Source code introduction

The demo shows a row-based waterfall view, which only supports ARC mode.

Source code screenshot:

[[128131]]

Source code snippet:

  1. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  2. {
  3. BDRowInfo *ri = [_rowInfos objectAtIndex:indexPath.row];
  4. static NSString *CellIdentifier = @ "Cell" ;
  5. BDDynamicGridCell *cell = [tableView dequeueReusableCellWithIdentifier:[CellIdentifier stringByAppendingFormat:@ "_viewCount%d" , ri.viewsPerCell]];
  6.       
  7. if (!cell) {
  8. cell = [[BDDynamicGridCell alloc] initWithLayoutStyle:BDDynamicGridCellLayoutStyleFill
  9. reuseIdentifier:CellIdentifier];
  10.           
  11. cell.viewBorderWidth = 1 ;
  12.           
  13. UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action: @selector (didLongPress:)];
  14. longPress.numberOfTouchesRequired = 1 ;
  15. [cell.gridContainerView addGestureRecognizer:longPress];
  16.           
  17. UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action: @selector (didDoubleTap:)];
  18. doubleTap.numberOfTapsRequired = 2 ;
  19. doubleTap.delaysTouchesBegan = YES;
  20. [cell.gridContainerView addGestureRecognizer:doubleTap];
  21.           
  22. UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action: @selector (didSingleTap:)];
  23. singleTap.numberOfTapsRequired = 1 ;
  24. singleTap.delaysTouchesBegan = YES;
  25. [cell.gridContainerView addGestureRecognizer:singleTap];
  26. [singleTap requireGestureRecognizerToFail:doubleTap];
  27. }
  28.       
  29. //clear for updated list of views  
  30. [cell setViews:nil];
  31. cell.viewBorderWidth = self.borderWidth;
  32. cell.backgroundColor = nil;
  33.   
  34. cell.rowInfo = ri;
  35. NSArray * viewsForRow = [NSArray array];
  36. for ( int i= 0 ; i<ri.viewspercell; i++)= "" {= "" viewsforrow= "[viewsForRow" arraybyaddingobject:[self.delegate= "" viewatindex:i= "" += "" ri.accumulatedviews= "" rowinfo:ri]];= "" }= "" nsassert(viewsforrow.count= "" > 0 , @ "number of views per row must be greater than 0" );
  37. [cell setViews:viewsForRow];
  38.       
  39. return cell;
  40. }</ri.viewspercell;>

Source code link: http://download..com/data/1984619

<<:  How did WeChat product managers and architects handle 1 billion red envelopes?

>>:  Douban Photo Album Collection

Recommend

Meizu and Xiaomi share the same roots but different fates

"We are of the same roots, why are we so anxi...

How do we measure the age of stars and planets?

Astronomers used the Hubble Telescope to take the...

Recommend 5 information flow advertising case libraries, take them for free!

It is really difficult to make information flow a...

How to Write an Integrated Marketing Communications Plan (Version 4.0)

1. Those who do not consider the overall situatio...