Skip to content

Commit

Permalink
Merge pull request #28 from sdkdimon/master
Browse files Browse the repository at this point in the history
Add to delegate methods UICollectionView and UICollectionViewLayout parameters.
  • Loading branch information
bryceredd committed Nov 24, 2014
2 parents 3ccf9a2 + 53e3319 commit 7876902
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
40 changes: 20 additions & 20 deletions QuiltDemo/RFViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions RFQuiltLayout/RFQuiltLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

@protocol RFQuiltLayoutDelegate <UICollectionViewDelegate>
@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
Expand Down
10 changes: 5 additions & 5 deletions RFQuiltLayout/RFQuiltLayout.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 7876902

Please sign in to comment.