Skip to content

Commit

Permalink
修改流式布局对最后一行的处理。
Browse files Browse the repository at this point in the history
  • Loading branch information
youngsoft committed Dec 23, 2019
1 parent d7ab375 commit 88f8306
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
2 changes: 1 addition & 1 deletion MyLayout/Lib/MyFlowLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
@property(nonatomic,assign) MyGravity arrangedGravity;

/**
指定流式布局最后一行的尺寸或间距的拉伸策略。默认值是MyGravityPolicy_No,表示最后一行的尺寸或间接拉伸策略不生效。如果布局只有一行则不会受到这个策略的影响
指定流式布局最后一行的尺寸或间距的拉伸策略。默认值是MyGravityPolicy_No表示最后一行的尺寸或间接拉伸策略不生效。
在流式布局中我们可以通过gravity属性来对每一行的尺寸或间距进行拉伸处理。但是在实际情况中最后一行的子视图数量可能会小于等于前面行的数量。
在这种情况下如果对最后一行进行相同的尺寸或间距的拉伸处理则有可能会影响整体的布局效果。因此我们可通过这个属性来指定最后一行的尺寸或间距的生效策略。
这个策略在不同的流式布局中效果不一样:
Expand Down
10 changes: 3 additions & 7 deletions MyLayout/Lib/MyFlowLayout.m
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,6 @@ - (void)myVertLayout:(MyFlowLayoutViewSizeClass*)lsc adjustSingleline:(NSInteger
//只有最后一行,并且数量小于arrangedCount,并且不是第一行才应用策略。
BOOL applyLastlineGravityPolicy = ((startItemIndex + count) == sbs.count &&
count != lsc.arrangedCount &&
startItemIndex != 0 &&
lineHorzGravity == MyGravity_Horz_Fill);


Expand Down Expand Up @@ -396,7 +395,6 @@ - (void)myHorzLayout:(MyFlowLayoutViewSizeClass*)lsc adjustSingleline:(NSInteger
//只有最后一行,并且数量小于arrangedCount,并且不是第一行才应用策略。
BOOL applyLastlineGravityPolicy = ((startItemIndex + count) == sbs.count &&
count != lsc.arrangedCount &&
startItemIndex != 0 &&
lineVertGravity == MyGravity_Vert_Fill);


Expand Down Expand Up @@ -532,7 +530,6 @@ - (void)myVertLayout:(MyFlowLayoutViewSizeClass*)lsc calcSingleline:(NSInteger)l
//只有最后一行,并且数量小于arrangedCount,并且不是第一行才应用策略。
BOOL applyLastlineGravityPolicy = ((startItemIndex + count) == sbs.count &&
count != lsc.arrangedCount &&
startItemIndex != 0 &&
(lineHorzGravity == MyGravity_Horz_Between || lineHorzGravity == MyGravity_Horz_Around || lineHorzGravity == MyGravity_Horz_Among));

switch (lineHorzGravity)
Expand Down Expand Up @@ -661,7 +658,7 @@ - (void)myVertLayout:(MyFlowLayoutViewSizeClass*)lsc calcSingleline:(NSInteger)l
}

sbvmyFrame.leading += addXPosInc * (itemIndex - startItemIndex);
if (applyLastlineGravityPolicy && lsc.lastlineGravityPolicy == MyGravityPolicy_Auto) {
if (lineIndex != 0 && applyLastlineGravityPolicy && lsc.lastlineGravityPolicy == MyGravityPolicy_Auto) {
//对齐前一行对应位置的
sbvmyFrame.leading = sbs[itemIndex - lsc.arrangedCount].myFrame.leading;
}
Expand Down Expand Up @@ -736,10 +733,9 @@ - (void)myHorzLayout:(MyFlowLayoutViewSizeClass*)lsc calcSingleline:(NSInteger)l
lineVertGravity = vertGravity;
}

//只有最后一行,并且数量小于arrangedCount,并且不是第一行才应用策略
//只有最后一行,并且数量小于arrangedCount才应用策略
BOOL applyLastlineGravityPolicy = ((startItemIndex + count) == sbs.count &&
count != lsc.arrangedCount &&
startItemIndex != 0 &&
(lineVertGravity == MyGravity_Vert_Between || lineVertGravity == MyGravity_Vert_Around || lineVertGravity == MyGravity_Vert_Among));


Expand Down Expand Up @@ -860,7 +856,7 @@ - (void)myHorzLayout:(MyFlowLayoutViewSizeClass*)lsc calcSingleline:(NSInteger)l
}

sbvmyFrame.top += addYPosInc * (itemIndex - startItemIndex);
if (applyLastlineGravityPolicy && lsc.lastlineGravityPolicy == MyGravityPolicy_Auto) {
if (lineIndex != 0 && applyLastlineGravityPolicy && lsc.lastlineGravityPolicy == MyGravityPolicy_Auto) {
//对齐前一行对应位置的
sbvmyFrame.top = sbs[itemIndex - lsc.arrangedCount].myFrame.top;
}
Expand Down

0 comments on commit 88f8306

Please sign in to comment.