2013-03-29 58 views

回答

1

我做這件事的方式hackish的(假定所有元素都具有相同大小):

- (void) countRowsAndColumns 
{ 
    NSArray *layouts = [collectionViewLayout layoutAttributesForElementsInRect:self.collectionView.bounds]; 
    NSMutableSet *columns = [NSMutableSet set]; 
    NSMutableSet *rows = [NSMutableSet set]; 
    for (UICollectionViewLayoutAttributes *layout in layouts) 
    { 
     if (layout.representedElementCategory != UICollectionElementCategoryCell) continue; 
     CGFloat x = layout.frame.origin.x; 
     [columns addObject:@(x)]; 
     CGFloat y = layout.frame.origin.y; 
     [rows addObject:@(y)]; 
    } 
    _columnCount = columns.count; 
    _rowCount = rows.count; 
} 
相關問題