This repository has been archived by the owner on Jan 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 166
/
Copy pathHATransitionLayout.m
executable file
·72 lines (58 loc) · 2.48 KB
/
HATransitionLayout.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
//
// HATransitionLayout.m
// Paper
//
// Created by Heberti Almeida on 11/02/14.
// Copyright (c) 2014 Heberti Almeida. All rights reserved.
//
#import "HATransitionLayout.h"
static NSString *kOffsetH = @"offsetH";
static NSString *kOffsetV = @"offsetV";
@implementation HATransitionLayout
// set the completion progress of the current transition.
//
- (void)setTransitionProgress:(CGFloat)transitionProgress
{
[super setTransitionProgress:transitionProgress];
// return the most recently set values for each key
CGFloat offsetH = [self valueForAnimatedKey:kOffsetH];
CGFloat offsetV = [self valueForAnimatedKey:kOffsetV];
_offset = UIOffsetMake(offsetH, offsetV);
}
// called by the HATransitionController class while updating its transition progress, animating
// the collection view items in an out of stack mode.
//
- (void)setOffset:(UIOffset)offset
{
// store the floating-point values with out meaningful keys for our transition layout object
[self updateValue:offset.horizontal forAnimatedKey:kOffsetH];
[self updateValue:offset.vertical forAnimatedKey:kOffsetV];
_offset = offset;
}
// return the layout attributes for all of the cells and views in the specified rectangle
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
NSArray *attributes = [super layoutAttributesForElementsInRect:rect];
for (UICollectionViewLayoutAttributes *currentAttribute in attributes)
{
if (currentAttribute.representedElementCategory != UICollectionElementCategorySupplementaryView) {
CGPoint currentCenter = currentAttribute.center;
CGPoint updatedCenter = CGPointMake(currentCenter.x, currentCenter.y + self.offset.vertical);
currentAttribute.center = updatedCenter;
}
if (currentAttribute.representedElementCategory == UICollectionElementCategorySupplementaryView) {
currentAttribute.frame = self.collectionView.bounds;
}
}
return attributes;
}
- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
{
// returns the layout attributes for the item at the specified index path
UICollectionViewLayoutAttributes *attributes = [super layoutAttributesForItemAtIndexPath:indexPath];
CGPoint currentCenter = attributes.center;
CGPoint updatedCenter = CGPointMake(currentCenter.x + self.offset.horizontal, currentCenter.y + self.offset.vertical);
attributes.center = updatedCenter;
return attributes;
}
@end