diff --git a/QuiltDemo/RFViewController.m b/QuiltDemo/RFViewController.m index 5ccae41..142812b 100644 --- a/QuiltDemo/RFViewController.m +++ b/QuiltDemo/RFViewController.m @@ -111,32 +111,32 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtInd #pragma mark – RFQuiltLayoutDelegate -- (CGSize) blockSizeForItemAtIndexPath:(NSIndexPath *)indexPath { - + +-(CGSize) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout blockSizeForItemAtIndexPath:(NSIndexPath *)indexPath{ if(indexPath.row >= self.numbers.count) { - NSLog(@"Asking for index paths of non-existant cells!! %d from %d cells", indexPath.row, self.numbers.count); + NSLog(@"Asking for index paths of non-existant cells!! %ld from %lu cells", (long)indexPath.row, (unsigned long)self.numbers.count); } CGFloat width = [[self.numberWidths objectAtIndex:indexPath.row] floatValue]; CGFloat height = [[self.numberHeights objectAtIndex:indexPath.row] floatValue]; return CGSizeMake(width, height); -// if (indexPath.row % 10 == 0) -// return CGSizeMake(3, 1); -// if (indexPath.row % 11 == 0) -// return CGSizeMake(2, 1); -// else if (indexPath.row % 7 == 0) -// return CGSizeMake(1, 3); -// else if (indexPath.row % 8 == 0) -// return CGSizeMake(1, 2); -// else if(indexPath.row % 11 == 0) -// return CGSizeMake(2, 2); -// if (indexPath.row == 0) return CGSizeMake(5, 5); -// -// return CGSizeMake(1, 1); -} - -- (UIEdgeInsets)insetsForItemAtIndexPath:(NSIndexPath *)indexPath { + // if (indexPath.row % 10 == 0) + // return CGSizeMake(3, 1); + // if (indexPath.row % 11 == 0) + // return CGSizeMake(2, 1); + // else if (indexPath.row % 7 == 0) + // return CGSizeMake(1, 3); + // else if (indexPath.row % 8 == 0) + // return CGSizeMake(1, 2); + // else if(indexPath.row % 11 == 0) + // return CGSizeMake(2, 2); + // if (indexPath.row == 0) return CGSizeMake(5, 5); + // + // return CGSizeMake(1, 1); +} + +- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetsForItemAtIndexPath:(NSIndexPath *)indexPath { return UIEdgeInsetsMake(2, 2, 2, 2); } @@ -151,7 +151,7 @@ - (void)addIndexPath:(NSIndexPath *)indexPath { isAnimating = YES; [self.collectionView performBatchUpdates:^{ - int index = indexPath.row; + NSInteger index = indexPath.row; [self.numbers insertObject:@(++num) atIndex:index]; [self.numberWidths insertObject:@(1 + arc4random() % 3) atIndex:index]; [self.numberHeights insertObject:@(1 + arc4random() % 3) atIndex:index]; diff --git a/RFQuiltLayout/RFQuiltLayout.h b/RFQuiltLayout/RFQuiltLayout.h index 50e2b36..d05387b 100644 --- a/RFQuiltLayout/RFQuiltLayout.h +++ b/RFQuiltLayout/RFQuiltLayout.h @@ -10,8 +10,8 @@ @protocol RFQuiltLayoutDelegate @optional -- (CGSize) blockSizeForItemAtIndexPath:(NSIndexPath *)indexPath; // defaults to 1x1 -- (UIEdgeInsets) insetsForItemAtIndexPath:(NSIndexPath *)indexPath; // defaults to uiedgeinsetszero +- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout blockSizeForItemAtIndexPath:(NSIndexPath *)indexPath; // defaults to 1x1 +- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetsForItemAtIndexPath:(NSIndexPath *)indexPath; // defaults to uiedgeinsetszero @end @interface RFQuiltLayout : UICollectionViewLayout diff --git a/RFQuiltLayout/RFQuiltLayout.m b/RFQuiltLayout/RFQuiltLayout.m index cf76ff2..3b44102 100644 --- a/RFQuiltLayout/RFQuiltLayout.m +++ b/RFQuiltLayout/RFQuiltLayout.m @@ -98,8 +98,9 @@ - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect { - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath { UIEdgeInsets insets = UIEdgeInsetsZero; - if([self.delegate respondsToSelector:@selector(insetsForItemAtIndexPath:)]) - insets = [self.delegate insetsForItemAtIndexPath:indexPath]; + if([self.delegate respondsToSelector:@selector(collectionView:layout:insetsForItemAtIndexPath:)]) + insets = [[self delegate] collectionView:[self collectionView] layout:self insetsForItemAtIndexPath:indexPath]; + CGRect frame = [self frameForIndexPath:indexPath]; UICollectionViewLayoutAttributes* attributes = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath]; @@ -391,9 +392,8 @@ - (CGRect) frameForIndexPath:(NSIndexPath*)path { - (CGSize)getBlockSizeForItemAtIndexPath:(NSIndexPath *)indexPath { CGSize blockSize = CGSizeMake(1, 1); - if([self.delegate respondsToSelector:@selector(blockSizeForItemAtIndexPath:)]) - blockSize = [self.delegate blockSizeForItemAtIndexPath:indexPath]; - + if([self.delegate respondsToSelector:@selector(collectionView:layout:blockSizeForItemAtIndexPath:)]) + blockSize = [[self delegate] collectionView:[self collectionView] layout:self blockSizeForItemAtIndexPath:indexPath]; return blockSize; }