Skip to content

Commit f2e7e59

Browse files
committed
优化部分代码
优化部分代码
1 parent 36da7ca commit f2e7e59

File tree

3 files changed

+10
-20
lines changed

3 files changed

+10
-20
lines changed

collectionView.xcodeproj/xcuserdata/wangshuanglong.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

-16
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,5 @@
1313
stopOnStyle = "0">
1414
</BreakpointContent>
1515
</BreakpointProxy>
16-
<BreakpointProxy
17-
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
18-
<BreakpointContent
19-
shouldBeEnabled = "Yes"
20-
ignoreCount = "0"
21-
continueAfterRunningActions = "No"
22-
filePath = "collectionView/VC/WSLFlowLayoutStyleOne.m"
23-
timestampString = "559814094.298077"
24-
startingColumnNumber = "9223372036854775807"
25-
endingColumnNumber = "9223372036854775807"
26-
startingLineNumber = "13"
27-
endingLineNumber = "13"
28-
landmarkName = "unknown"
29-
landmarkType = "0">
30-
</BreakpointContent>
31-
</BreakpointProxy>
3216
</Breakpoints>
3317
</Bucket>

collectionView/VC/WSLFlowLayoutStyleOne.m

+10-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
@interface WSLWaterFlowLayoutStyleOne ()<UICollectionViewDelegate, UICollectionViewDataSource,WSLWaterFlowLayoutDelegate>
1515
{
1616
WSLWaterFlowLayout * _flow;
17+
NSMutableArray * _array;
1718
}
1819
@end
1920

@@ -25,6 +26,11 @@ - (void)viewDidLoad {
2526
self.navigationItem.title = [NSString stringWithFormat:@"样式%d",self.flowLayoutStyle];
2627
self.view.backgroundColor = [UIColor grayColor];
2728

29+
_array = [NSMutableArray array];
30+
for (int i = 0 ; i < 2 * 30; i++) {
31+
[_array addObject:@(arc4random()%200)];
32+
}
33+
2834
_flow = [[WSLWaterFlowLayout alloc] init];
2935
_flow.delegate = self;
3036
_flow.flowLayoutStyle = self.flowLayoutStyle;
@@ -73,11 +79,11 @@ - (NSArray *)proportionsForItem{
7379
//返回每个item大小
7480
- (CGSize)waterFlowLayout:(WSLWaterFlowLayout *)waterFlowLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
7581
if(waterFlowLayout.flowLayoutStyle == (WSLWaterFlowLayoutStyle)0){
76-
return CGSizeMake(0, arc4random() % 200);
82+
return CGSizeMake(0, [_array[indexPath.section * 10 + indexPath.row] floatValue]);
7783
}else if (waterFlowLayout.flowLayoutStyle == (WSLWaterFlowLayoutStyle)1){
78-
return CGSizeMake(arc4random() % 200, 0);
84+
return CGSizeMake([_array[indexPath.section * 10 + indexPath.row] floatValue], 0);
7985
}else if (waterFlowLayout.flowLayoutStyle == (WSLWaterFlowLayoutStyle)2){
80-
return CGSizeMake(arc4random() % 200, 100);
86+
return CGSizeMake([_array[indexPath.section * 10 + indexPath.row] floatValue], 100);
8187
}else if (waterFlowLayout.flowLayoutStyle == (WSLWaterFlowLayoutStyle)3){
8288
//每一个最小的正方形单元格的边长
8389
CGFloat average = (self.view.frame.size.width - [self edgeInsetInWaterFlowLayout:waterFlowLayout].left * 2 - 3 * [self columnMarginInWaterFlowLayout:waterFlowLayout])/4.0;
@@ -130,7 +136,7 @@ - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
130136
if (_flow.flowLayoutStyle == (WSLWaterFlowLayoutStyle)3){
131137
return 1;
132138
}
133-
return 3;
139+
return _array.count/10;
134140
}
135141

136142
//组内成员个数

0 commit comments

Comments
 (0)