You can get the position of an element after placing it with [myCollectionView.collectionViewLayout layoutAttributesForItemAtIndexPath:]
, , Y- . , , .
:
NSInteger totalItems = [myCollectionView numberOfItemsInSection:0];
NSInteger currItem;
CGFloat currRowOriginY = CGFLOAT_MAX;
for (currItem = 0; currItem < totalItems; currItem++) {
UICollectionViewLayoutAttributes *attributes =
[collectionView.collectionViewLayout layoutAttributesForItemAtIndexPath:
[NSIndexPath indexPathForItem:currItem inSection:0]];
if (currItem == 0) {
currRowOriginY = attributes.frame.origin.y;
continue;
}
if (attributes.frame.origin.y > currRowOriginY + 5.0f) {
break;
}
}
NSLog(@"new row started at item %ld", (long)currItem);
NSInteger totalRows = totalItems / currItem;
NSLog(@"%ld rows", (long)totalRows);
,
NSInteger totalItems = [self.timelineCollectionView numberOfItemsInSection:0];
NSIndexPath lastIndex = [NSIndexPath indexPathForItem:totalItems - 1 inSection:0];
UICollectionViewLayoutAttributes *attributes =
[myCollectionView.collectionViewLayout layoutAttributesForItemAtIndexPath:lastIndex];
. . UICollectionViewFlowLayout.
UICollectionViewFlowLayout *myFlowLayout = (UICollectionViewFlowLayout*)myCollectionView.collectionViewFlowLayout;
myFlowLayout.headerReferenceSize
myFlowLayout.minimumLineSpacing
..