-
Notifications
You must be signed in to change notification settings - Fork 0
/
CardingInitialLayout.m
110 lines (81 loc) · 3.52 KB
/
CardingInitialLayout.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//
// CardingInitialLayout.m
// Carding
//
// Created by Zsolt Kiraly on 9/26/13.
// Copyright (c) 2013 resetBit. All rights reserved.
//
#import "CardingInitialLayout.h"
#import "CardingCell.h"
@implementation CardingInitialLayout {
NSMutableArray *_attributesArray;
}
- (void)prepareLayout {
[super prepareLayout];
self.minimumLineSpacing = 5;
self.itemSize = CGSizeMake(320.0, 192.0);
// We only display one section in this layout.
NSInteger itemCount = [self.collectionView numberOfItemsInSection:0];
if (!_attributesArray) {
_attributesArray = [[NSMutableArray alloc] initWithCapacity:itemCount];
}
CGFloat yPos = 0.0;
for (NSInteger i = 0; i < itemCount; i ++) {
UICollectionViewLayoutAttributes *attributes = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:[NSIndexPath indexPathForItem:i inSection:0]];
CGRect newFrame = CGRectMake(0.0, yPos, 320.0, 192.0);
yPos += 72.0;
attributes.frame = newFrame;
//attributes.transform3D = CATransform3DMakeScale(0.96, 0.96, 0.96);
//attributes.transform3D = CATransform3DRotate(attributes.transform3D, -15*3.14/180.0, 1.0, 0.0, 0.0);
attributes.zIndex = itemCount;
[_attributesArray addObject:attributes];
}
}
#if 0
- (void)prepareForTransitionFromLayout:(UICollectionViewLayout *)oldLayout {
[super prepareForTransitionFromLayout:oldLayout];
NSInteger itemCount = [self.collectionView numberOfItemsInSection:0];
if (!_attributesArray) {
_attributesArray = [[NSMutableArray alloc] initWithCapacity:itemCount];
}
for (UICollectionViewLayoutAttributes *attrib in _attributesArray)
{
CardingCell *cell = (CardingCell *)[self.collectionView cellForItemAtIndexPath:attrib.indexPath];
long realZIndex = cell.indexPath.item + 1;
attrib.zIndex = realZIndex;
attrib.transform3D = CATransform3DMakeTranslation(0, 0, realZIndex);
}
}
#endif
- (CGSize)collectionViewContentSize {
//return CGSizeMake(320.0, 1500.0);
return [super collectionViewContentSize];
}
-(NSArray*)layoutAttributesForElementsInRect:(CGRect)rect
{
//return [super layoutAttributesForElementsInRect:rect];
NSMutableArray *returnArray = [[NSMutableArray alloc] initWithCapacity:_attributesArray.count];
for (UICollectionViewLayoutAttributes *attrib in _attributesArray)
{
// preserve the correct z order (from SO)
attrib.zIndex = attrib.indexPath.item + 1;
// is it in the rect?
if (CGRectIntersectsRect(rect, attrib.frame)) {
NSLog(@"CardingInitialLayout layoutAttributesForElementsInRect:\nfor item %@ set zIndex to %lu", attrib.indexPath, attrib.zIndex);
NSLog(@"hidden: %s", attrib.hidden ? "YES" : "NO");
[returnArray addObject:attrib];
}
}
return returnArray;
}
- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewLayoutAttributes *attrib = [_attributesArray objectAtIndex:indexPath.item];
// preserve the correct z order (from SO)
attrib.transform3D = CATransform3DMakeTranslation(0, 0, attrib.indexPath.item);
//attrib.zIndex = indexPath.item + 1;
NSLog(@"CardingInitialLayout layoutAttributesForItemAtIndexPath:\nfor item %@ set zIndex to %lu", attrib.indexPath, attrib.zIndex);
NSLog(@"hidden: %s", attrib.hidden ? "YES" : "NO");
return attrib;
}
@end