源码简介
demo展示以行为主(row)的瀑布流样式视图,只支持ARC模式。
源码截图:
源码片段:
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- BDRowInfo *ri = [_rowInfos objectAtIndex:indexPath.row];
- static NSString *CellIdentifier = @"Cell";
- BDDynamicGridCell *cell = [tableView dequeueReusableCellWithIdentifier:[CellIdentifier stringByAppendingFormat:@"_viewCount%d", ri.viewsPerCell]];
- if (!cell) {
- cell = [[BDDynamicGridCell alloc] initWithLayoutStyle:BDDynamicGridCellLayoutStyleFill
- reuseIdentifier:CellIdentifier];
- cell.viewBorderWidth = 1;
- UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(didLongPress:)];
- longPress.numberOfTouchesRequired = 1;
- [cell.gridContainerView addGestureRecognizer:longPress];
- UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didDoubleTap:)];
- doubleTap.numberOfTapsRequired = 2;
- doubleTap.delaysTouchesBegan = YES;
- [cell.gridContainerView addGestureRecognizer:doubleTap];
- UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didSingleTap:)];
- singleTap.numberOfTapsRequired = 1;
- singleTap.delaysTouchesBegan = YES;
- [cell.gridContainerView addGestureRecognizer:singleTap];
- [singleTap requireGestureRecognizerToFail:doubleTap];
- }
- //clear for updated list of views
- [cell setViews:nil];
- cell.viewBorderWidth = self.borderWidth;
- cell.backgroundColor = nil;
- cell.rowInfo = ri;
- NSArray * viewsForRow = [NSArray array];
- 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");
- [cell setViews:viewsForRow];
- return cell;
- }</ri.viewspercell;>