2013-03-29 3 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; 
}