Skip to content

Commit 2423be4

Browse files
committed
优化
1 parent 52fb254 commit 2423be4

File tree

8 files changed

+47
-37
lines changed

8 files changed

+47
-37
lines changed

Example/FMLayoutKit/FMAddViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ - (void)viewDidLoad {
164164
section.cellElement = [FMLayoutElement elementWithViewClass:[FMCollectionCustomCell class]];
165165
[section setClickCellBlock:^(FMLayoutBaseSection * _Nonnull section, NSInteger item) {
166166
FMHorizontalLayoutController *vc = [[FMHorizontalLayoutController alloc] init];
167-
[self.navigationController pushViewController:vc animated:YES];
167+
[weakSelf.navigationController pushViewController:vc animated:YES];
168168
}];
169169
[self.shareSections addObject:section];
170170
// self.firstSection = section;

Example/FMLayoutKit/FMViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ - (void)viewDidLoad {
7777
self.sections = [NSMutableArray array];
7878
__weak typeof(self) weakSelf = self;
7979
// [FMLayoutDebugLog closeLog];
80-
// FMLayoutCloseLog();
80+
// FMLayoutOpenLog();
8181
{
8282
FMLayoutDynamicSection *section = [FMLayoutDynamicSection sectionWithSectionInset:UIEdgeInsetsMake(5, 15, 5, 15) itemSpace:10 lineSpace:10 column:2];
8383

Example/FMLayoutKit/LS_HomeActivityCell.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212

1313
@implementation LS_HomeActivityCell
1414

15+
- (void)dealloc{
16+
17+
}
18+
1519
- (instancetype)initWithFrame:(CGRect)frame
1620
{
1721
self = [super initWithFrame:frame];

FMLayoutKit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'FMLayoutKit'
11-
s.version = '1.1.5'
11+
s.version = '1.1.6'
1212
s.summary = 'A short description of FMLayoutKit.'
1313

1414
# This description is used to generate tags and improve search results.

FMLayoutKit/Classes/Sections/FMLayoutDynamicSection.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ typedef CGFloat(^FMLayoutItemOtherBlock)(id section, NSInteger item);
3030
///block返回手动计算的高度 优先级比自动的高
3131
@property(nonatomic, copy)FMLayoutItemOtherBlock otherBlock;
3232

33+
- (CGFloat)autoHeightVerticalWithWidth:(CGFloat)fixedWidth index:(NSInteger)index;
34+
3335
@end
3436

3537
NS_ASSUME_NONNULL_END

FMLayoutKit/Classes/Sections/FMLayoutDynamicSection.m

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,43 @@
1313

1414
@interface FMLayoutDynamicSection ()
1515

16+
@property(nonatomic, strong)NSMapTable *autoHeightCells;
17+
1618
@end
1719

1820
@implementation FMLayoutDynamicSection
1921

22+
- (NSMapTable *)autoHeightCells{
23+
if (_autoHeightCells == nil) {
24+
_autoHeightCells = [NSMapTable mapTableWithKeyOptions:NSPointerFunctionsWeakMemory valueOptions:NSPointerFunctionsStrongMemory];
25+
}
26+
return _autoHeightCells;
27+
}
28+
29+
- (CGFloat)autoHeightVerticalWithWidth:(CGFloat)fixedWidth index:(NSInteger)index{
30+
CGFloat itemOther = 0;
31+
if (self.direction == FMLayoutDirectionHorizontal) {
32+
@throw [NSException exceptionWithName:@"autoHeightFixedWidth must for FMLayoutDirectionVertical" reason:@"FMLayoutDynamicSection" userInfo:nil];
33+
}
34+
if (self.deqCellReturnElement) {
35+
FMLayoutElement *element = self.deqCellReturnElement(self, index);
36+
UICollectionViewCell *cell = [self.autoHeightCells objectForKey:element.viewClass];
37+
if (cell == nil) {
38+
if (element.isNib) {
39+
cell = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(element.viewClass) owner:nil options:nil] lastObject];
40+
} else {
41+
cell = [[element.viewClass alloc] init];
42+
}
43+
[self.autoHeightCells setObject:cell forKey:element.viewClass];
44+
}
45+
if (self.configurationCell) {
46+
self.configurationCell(self ,cell, index);
47+
}
48+
itemOther = [cell systemLayoutSizeFittingSize:CGSizeMake(fixedWidth, MAXFLOAT)].height;
49+
}
50+
return itemOther;
51+
}
52+
2053
- (id)copyWithZone:(NSZone *)zone{
2154
FMLayoutDynamicSection *section = [super copyWithZone:zone];
2255
section.autoHeightFixedWidth = self.autoHeightFixedWidth;
@@ -64,22 +97,7 @@ - (FMCollectionLayoutAttributes *)getItemAttributesWithIndex:(NSInteger)j{
6497
CGFloat itemFixed = self.cellFixedSize;
6598
CGFloat itemOther = 0;
6699
if (self.autoHeightFixedWidth) {
67-
if (self.direction == FMLayoutDirectionHorizontal) {
68-
@throw [NSException exceptionWithName:@"autoHeightFixedWidth must for FMLayoutDirectionVertical" reason:@"FMLayoutDynamicSection" userInfo:nil];
69-
}
70-
if (self.deqCellReturnElement) {
71-
UICollectionViewCell *cell;
72-
FMLayoutElement *element = self.deqCellReturnElement(self, j);
73-
if (element.isNib) {
74-
cell = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(element.viewClass) owner:nil options:nil] lastObject];
75-
} else {
76-
cell = [[element.viewClass alloc] init];
77-
}
78-
if (self.configurationCell) {
79-
self.configurationCell(self ,cell, j);
80-
}
81-
itemOther = [cell systemLayoutSizeFittingSize:CGSizeMake(itemFixed, MAXFLOAT)].height;
82-
}
100+
itemOther = [self autoHeightVerticalWithWidth:itemFixed index:j];
83101
} else {
84102
itemOther = !self.otherBlock?0:self.otherBlock(self, j);
85103
}
@@ -106,8 +124,6 @@ - (FMCollectionLayoutAttributes *)getItemAttributesWithIndex:(NSInteger)j{
106124
return itemAttr;
107125
}
108126

109-
110-
111127
- (UICollectionViewCell *)dequeueReusableCellForIndexPath:(NSIndexPath *)indexPath collectionView:(nonnull UICollectionView *)collectionView{
112128
return [collectionView dequeueReusableCellWithReuseIdentifier:self.deqCellReturnElement(self, indexPath.item).reuseIdentifier forIndexPath:indexPath];
113129
}

FMLayoutKit/Classes/Sections/FMLayoutScaleSection.m

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -114,22 +114,7 @@ - (FMCollectionLayoutAttributes *)getItemAttributesWithIndex:(NSInteger)j{
114114
CGFloat itemFixed = model.fixedSize;
115115
CGFloat itemOther = 0;
116116
if (self.autoHeightFixedWidth) {
117-
if (self.direction == FMLayoutDirectionHorizontal) {
118-
@throw [NSException exceptionWithName:@"autoHeightFixedWidth must for FMLayoutDirectionVertical" reason:@"FMLayoutDynamicSection" userInfo:nil];
119-
}
120-
if (self.deqCellReturnElement) {
121-
UICollectionViewCell *cell;
122-
FMLayoutElement *element = self.deqCellReturnElement(self, j);
123-
if (element.isNib) {
124-
cell = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(element.viewClass) owner:nil options:nil] lastObject];
125-
} else {
126-
cell = [[element.viewClass alloc] init];
127-
}
128-
if (self.configurationCell) {
129-
self.configurationCell(self ,cell, j);
130-
}
131-
itemOther = [cell systemLayoutSizeFittingSize:CGSizeMake(itemFixed, MAXFLOAT)].height;
132-
}
117+
itemOther = [self autoHeightVerticalWithWidth:itemFixed index:j];
133118
} else {
134119
itemOther = !self.otherBlock?0:self.otherBlock(self, j);
135120
}

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ multi.dataSource = self;
209209

210210
```
211211
#### 版本更新
212+
2020-08-02(1.1.6)
213+
自动计算高度优化
214+
212215
2020-07-24(1.1.3)
213216
iOS10,11自动计算高度奔溃的问题修复
214217

0 commit comments

Comments
 (0)