Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add to delegate methods UICollectionView and UICollectionViewLayout parameters. #28

Merged
merged 1 commit into from
Nov 24, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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