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

A preview of the top five trends on Xiaohongshu during Double Eleven!

The closing ceremony of the Tokyo Olympics ended ...

Mobei Class 6th Foreign Trade SEO Optimization Promotion Google SEO (Google SEO)

Mobei Class 6th Foreign Trade SEO Optimization Pr...

On my journey after quitting my job: I wrote an app and started a company

[[127859]] A year ago, I left San Francisco, sold...

Microsoft CEO: If OEMs don't make Lumia phones, we'll do it ourselves

[[140618]] Since the market share has not increas...

Is WeChat launching live streaming to challenge TikTok and Kuaishou?

During the National Day holiday, WeChat quietly l...

From variable declaration in C language to block syntax in Objective-C

[[164693]] In this article, we start with simple ...

Is your phone outdated?

Nowadays, mobile phones are updated too quickly. H...

iOS 8 has a penetration rate of 82%, while Android 5.0 has only 1.6%.

According to Apple's App Store support page f...