-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomLayout.m
45 lines (37 loc) · 1.55 KB
/
CustomLayout.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//
// CustomLayout.m
// CollectionViewApp
//
// Created by Montana Burr on 8/15/15.
// Copyright (c) 2015 Montana. All rights reserved.
//
#import "CustomLayout.h"
@implementation CustomLayout
@synthesize delegate;
-(void)prepareLayout
{
NSAssert(delegate != nil,@"Delegate property must be set.");
NSAssert([delegate usableViews] != nil,@"Delegate must implement usableViews.");
NSAssert([[delegate usableViews] count] > 0, @"Delegate's usableViews method returns nothing.");
}
-(NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
NSMutableArray *attributesObjects = [[NSMutableArray alloc] init];
for (UIView *view in [delegate usableViews]) {
NSInteger tag = [view tag];
UICollectionViewLayoutAttributes *attrObj = [self layoutAttributesForPlaceholderView:[[delegate view] viewWithTag:tag]];
[attributesObjects addObject:attrObj];
}
return attributesObjects;
}
-(UICollectionViewLayoutAttributes *)layoutAttributesForPlaceholderView:(UIView *)placeholderView
{
NSInteger tag = [placeholderView tag];
UICollectionViewLayoutAttributes *attributesObject = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:[NSIndexPath indexPathForItem:(tag % 10) inSection:(tag / 10)]];
UICollectionView *collectionView = [self collectionView];
CGRect convertedFrame = [collectionView convertRect:placeholderView.frame fromView:collectionView.superview];
[attributesObject setFrame:convertedFrame];
[placeholderView removeFromSuperview];
return attributesObject;
}
@end