This repository was archived by the owner on Jan 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZoeLayout.m
More file actions
95 lines (69 loc) · 2.79 KB
/
ZoeLayout.m
File metadata and controls
95 lines (69 loc) · 2.79 KB
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
//
// ZoeLayout.m
// TestCyleImage
//
// Created by zhangwei on 16/4/10.
// Copyright © 2016年 zhangwei. All rights reserved.
//
#import "ZoeLayout.h"
@implementation ZoeLayout
- (void)prepareLayout
{
[super prepareLayout];
}
- (nullable NSArray<__kindof UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect
{
NSArray *original = [super layoutAttributesForElementsInRect:rect];
NSArray *temp = [[NSArray alloc]initWithArray:original copyItems:YES];
for (int i = 0; i < temp.count; i ++) {
UICollectionViewLayoutAttributes *att = temp[i];
CGFloat distance = ABS(att.center.x - self.collectionView.frame.size.width * 0.5 - self.collectionView.contentOffset.x);
CGFloat scale = 0.1;
CGFloat w = (self.collectionView.frame.size.width + self.itemSize.width) * 0.5;
if (distance >= w) {
scale = 0.1;
}else{
scale = scale + (1- distance / w ) * 1.3;
}
CGFloat angle = 1.0;
CGFloat angleW = (self.collectionView.frame.size.width - self.itemSize.width) * 0.5;
if (distance >= angleW) {
angle = 1.0;
}else{
angle = distance / angleW ;
}
CGFloat m34 = 800;
CGFloat value = 360 * angle;
CATransform3D transfrom =CATransform3DIdentity;
transfrom.m34 = 1.0 /m34;
CGFloat radiants= value / 360.0 * 2 * M_PI;
transfrom = CATransform3DRotate(transfrom, radiants,0.0f, 3.0f, 0.0f);
transfrom = CATransform3DScale(transfrom, scale, scale, 1);
att.transform3D = transfrom;
if (att.center.x == self.collectionView.center.x) {
}
}
return temp;
}
- (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset withScrollingVelocity:(CGPoint)velocity
{
CGRect rect;
rect.origin = proposedContentOffset;
rect.size = self.collectionView.frame.size;
NSArray *tempArray = [super layoutAttributesForElementsInRect:rect];
CGFloat gap = 1000;
CGFloat a = 0;
for (int i = 0; i < tempArray.count; i++) {
if (gap > ABS([(UIView *)tempArray[i] center].x - proposedContentOffset.x - self.collectionView.frame.size.width * 0.5)) {
gap = ABS([(UIView *)tempArray[i] center].x - proposedContentOffset.x - self.collectionView.frame.size.width * 0.5);
a = [(UIView *)tempArray[i] center].x - proposedContentOffset.x - self.collectionView.frame.size.width * 0.5;
}
}
CGPoint point =CGPointMake(proposedContentOffset.x + a , proposedContentOffset.y);
return point;
}
- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds
{
return YES;
}
@end