Skip to content

Commit

Permalink
功能升级,BUG修复。
Browse files Browse the repository at this point in the history
  • Loading branch information
youngsoft committed Nov 15, 2019
1 parent cc0fd65 commit 01c88a9
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 22 deletions.
21 changes: 19 additions & 2 deletions MyLayout/Lib/MyFloatLayout.m
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ -(CGSize)myVertOrientationLayout:(MyFloatLayoutViewSizeClass*)lsc calcRectOfSubv
// CGFloat paddingVert = paddingTop + paddingBottom;

//如果没有边界限制我们将宽度设置为最大。。
BOOL isBeyondFlag = NO; //子视图是否超出剩余空间需要换行。
if (lsc.widthSizeInner.dimeWrapVal)
{
//如果有最大限制则取最大值,解决那种宽度自适应,但是有最大值需要换行的情况。
Expand Down Expand Up @@ -630,6 +631,10 @@ -(CGSize)myVertOrientationLayout:(MyFloatLayoutViewSizeClass*)lsc calcRectOfSubv
trailingCandidateXBoundary = trailingPoint.x;
break;
}
else
{//这里表明剩余空间放不下了。
isBeyondFlag = YES;
}

nextPoint.y = CGRectGetMaxY(candidateRect);
}
Expand Down Expand Up @@ -750,7 +755,11 @@ -(CGSize)myVertOrientationLayout:(MyFloatLayoutViewSizeClass*)lsc calcRectOfSubv

maxWidth += paddingTrailing;
if (lsc.widthSizeInner.dimeWrapVal)
selfSize.width = maxWidth;
{
//只有在设置了最大宽度限制并且超出了才认为最大宽度是限制宽度,否则是最大子视图宽度。
if (selfSize.width == CGFLOAT_MAX || !isBeyondFlag)
selfSize.width = maxWidth;
}

maxHeight += paddingBottom;
if (lsc.heightSizeInner.dimeWrapVal)
Expand Down Expand Up @@ -876,6 +885,7 @@ -(CGSize)myHorzOrientationLayout:(MyFloatLayoutViewSizeClass*)lsc calcRectOfSubv
CGFloat paddingVert = paddingTop + paddingBottom;

//如果没有边界限制我们将高度设置为最大。。
BOOL isBeyondFlag = NO; //子视图是否超出剩余空间需要换行。
if (lsc.heightSizeInner.dimeWrapVal)
{
//如果有最大限制则取最大值,解决那种高度自适应,但是有最大值需要换行的情况。
Expand Down Expand Up @@ -1092,6 +1102,10 @@ -(CGSize)myHorzOrientationLayout:(MyFloatLayoutViewSizeClass*)lsc calcRectOfSubv
bottomCandidateYBoundary = bottomPoint.y;
break;
}
else
{
isBeyondFlag = YES;
}

nextPoint.x = CGRectGetMaxX(candidateRect);
}
Expand Down Expand Up @@ -1204,7 +1218,10 @@ -(CGSize)myHorzOrientationLayout:(MyFloatLayoutViewSizeClass*)lsc calcRectOfSubv

maxHeight += paddingBottom;
if (lsc.heightSizeInner.dimeWrapVal)
selfSize.height = maxHeight;
{
if (selfSize.height == CGFLOAT_MAX || !isBeyondFlag)
selfSize.height = maxHeight;
}

maxWidth += paddingTrailing;
if (lsc.widthSizeInner.dimeWrapVal)
Expand Down
18 changes: 16 additions & 2 deletions MyLayoutTests/MyFloatLayoutTestCase.m
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,17 @@ -(void)testWrapAndMaxMinLimit
MyRectAssert(rootLayout, CGRectMake(0, 0, 5+30+20+10+10, 10+30+5));

UIView *v3 = [UIView new];
v3.clearFloat = YES;
v3.mySize = CGSizeMake(50, 50);
[rootLayout addSubview:v3];
[rootLayout layoutIfNeeded];
MyRectAssert(rootLayout, CGRectMake(0, 0, 75, 10+30+20+50+5));
MyRectAssert(rootLayout, CGRectMake(0, 0, 5+30+20+10+10, 10+30+20+50+5));

UIView *v4 = [UIView new];
v4.mySize = CGSizeMake(50, 50);
[rootLayout addSubview:v4];
[rootLayout layoutIfNeeded];
MyRectAssert(rootLayout, CGRectMake(0, 0, 80, 10+30+20+50+20+50+5));
}

{
Expand All @@ -443,10 +450,17 @@ -(void)testWrapAndMaxMinLimit
MyRectAssert(rootLayout, CGRectMake(0, 0, 10+30+5,5+30+20+10+10));

UIView *v3 = [UIView new];
v3.clearFloat = YES;
v3.mySize = CGSizeMake(50, 50);
[rootLayout addSubview:v3];
[rootLayout layoutIfNeeded];
MyRectAssert(rootLayout, CGRectMake(0, 0, 10+30+20+50+5,75));
MyRectAssert(rootLayout, CGRectMake(0, 0,10+30+20+50+5,5+30+20+10+10));

UIView *v4 = [UIView new];
v4.mySize = CGSizeMake(50, 50);
[rootLayout addSubview:v4];
[rootLayout layoutIfNeeded];
MyRectAssert(rootLayout, CGRectMake(0, 0, 10+30+20+50+20+50+5,80));
}

}
Expand Down
7 changes: 7 additions & 0 deletions MyLayoutTests/MyFlowLayoutTestCase.m
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,13 @@ -(void)testRightAndBottomGravity
}
}

-(void)testFillAndStretch
{
//测试填充和拉伸。垂直数量约束流式布局的行内拉升和填充。以及整体


}

-(void)testFlex1
{
//测试内容约束布局下的尺寸自适应,以及最大最小值设置的场景。
Expand Down
36 changes: 18 additions & 18 deletions MyLayoutTests/MyLinearLayoutTestCase.m
Original file line number Diff line number Diff line change
Expand Up @@ -503,11 +503,11 @@ -(void)testFillAndStretch

XCTAssertTrue(CGRectEqualToRect(rootLayout.frame, CGRectMake(0,0,190,400)), @"the rootLayout.frame = %@",NSStringFromCGRect(rootLayout.frame));

XCTAssertTrue(CGRectEqualToRect(v1.frame, CGRectMake(20,10,140,20.5)), @"the v1.frame = %@",NSStringFromCGRect(v1.frame));
XCTAssertTrue(CGRectEqualToRect(v2.frame, CGRectMake(100,30.5,50,67.5)), @"the v2.frame = %@",NSStringFromCGRect(v2.frame));
XCTAssertTrue(CGRectEqualToRect(v3.frame, CGRectMake(55,98,70,107.5)), @"the v3.frame = %@",NSStringFromCGRect(v3.frame));
XCTAssertTrue(CGRectEqualToRect(v4.frame, CGRectMake(40,205.5,100,67.5)), @"the v4 .frame = %@",NSStringFromCGRect(v4.frame));
XCTAssertTrue(CGRectEqualToRect(v5.frame, CGRectMake(10,272.5,80,107.5)), @"the v5 .frame = %@",NSStringFromCGRect(v5.frame));
XCTAssertTrue(CGRectEqualToRect(v1.frame, CGRectMake(20,10,140,74.5)), @"the v1.frame = %@",NSStringFromCGRect(v1.frame));
XCTAssertTrue(CGRectEqualToRect(v2.frame, CGRectMake(100,84.5,50,54)), @"the v2.frame = %@",NSStringFromCGRect(v2.frame));
XCTAssertTrue(CGRectEqualToRect(v3.frame, CGRectMake(55,138.5,70,94)), @"the v3.frame = %@",NSStringFromCGRect(v3.frame));
XCTAssertTrue(CGRectEqualToRect(v4.frame, CGRectMake(40,232,100,54)), @"the v4 .frame = %@",NSStringFromCGRect(v4.frame));
XCTAssertTrue(CGRectEqualToRect(v5.frame, CGRectMake(10,286,80,94)), @"the v5 .frame = %@",NSStringFromCGRect(v5.frame));
}

if (1){
Expand Down Expand Up @@ -553,10 +553,10 @@ -(void)testFillAndStretch

XCTAssertTrue(CGRectEqualToRect(rootLayout.frame, CGRectMake(0,0,190,400)), @"the rootLayout.frame = %@",NSStringFromCGRect(rootLayout.frame));

XCTAssertTrue(CGRectEqualToRect(v1.frame, CGRectMake(20,10,140,20.5)), @"the v1.frame = %@",NSStringFromCGRect(v1.frame));
XCTAssertTrue(CGRectEqualToRect(v2.frame, CGRectMake(100,30.5,50,135)), @"the v2.frame = %@",NSStringFromCGRect(v2.frame));
XCTAssertTrue(CGRectEqualToRect(v3.frame, CGRectMake(55,165.5,70,40)), @"the v3.frame = %@",NSStringFromCGRect(v3.frame));
XCTAssertTrue(CGRectEqualToRect(v4.frame, CGRectMake(40,205.5,100,135)), @"the v4 .frame = %@",NSStringFromCGRect(v4.frame));
XCTAssertTrue(CGRectEqualToRect(v1.frame, CGRectMake(20,10,140,110.5)), @"the v1.frame = %@",NSStringFromCGRect(v1.frame));
XCTAssertTrue(CGRectEqualToRect(v2.frame, CGRectMake(100,120.5,50,90)), @"the v2.frame = %@",NSStringFromCGRect(v2.frame));
XCTAssertTrue(CGRectEqualToRect(v3.frame, CGRectMake(55,210,70,40)), @"the v3.frame = %@",NSStringFromCGRect(v3.frame));
XCTAssertTrue(CGRectEqualToRect(v4.frame, CGRectMake(40,250,100,90)), @"the v4 .frame = %@",NSStringFromCGRect(v4.frame));
XCTAssertTrue(CGRectEqualToRect(v5.frame, CGRectMake(10,340,80,40)), @"the v5 .frame = %@",NSStringFromCGRect(v5.frame));
}

Expand Down Expand Up @@ -604,11 +604,11 @@ -(void)testFillAndStretch

XCTAssertTrue(CGRectEqualToRect(rootLayout.frame, CGRectMake(0,0,400,190)), @"the rootLayout.frame = %@",NSStringFromCGRect(rootLayout.frame));

XCTAssertTrue(CGRectEqualToRect(v1.frame, CGRectMake(10,20,35,140)), @"the v1.frame = %@",NSStringFromCGRect(v1.frame));
XCTAssertTrue(CGRectEqualToRect(v2.frame, CGRectMake(45,100,64,50)), @"the v2.frame = %@",NSStringFromCGRect(v2.frame));
XCTAssertTrue(CGRectEqualToRect(v3.frame, CGRectMake(109,55,104,70)), @"the v3.frame = %@",NSStringFromCGRect(v3.frame));
XCTAssertTrue(CGRectEqualToRect(v4.frame, CGRectMake(212.5,40,64,100)), @"the v4 .frame = %@",NSStringFromCGRect(v4.frame));
XCTAssertTrue(CGRectEqualToRect(v5.frame, CGRectMake(276.5,10,104,80)), @"the v5 .frame = %@",NSStringFromCGRect(v5.frame));
XCTAssertTrue(CGRectEqualToRect(v1.frame, CGRectMake(10,20,86,140)), @"the v1.frame = %@",NSStringFromCGRect(v1.frame));
XCTAssertTrue(CGRectEqualToRect(v2.frame, CGRectMake(96,100,51,50)), @"the v2.frame = %@",NSStringFromCGRect(v2.frame));
XCTAssertTrue(CGRectEqualToRect(v3.frame, CGRectMake(147,55,91,70)), @"the v3.frame = %@",NSStringFromCGRect(v3.frame));
XCTAssertTrue(CGRectEqualToRect(v4.frame, CGRectMake(238,40,51,100)), @"the v4 .frame = %@",NSStringFromCGRect(v4.frame));
XCTAssertTrue(CGRectEqualToRect(v5.frame, CGRectMake(289,10,91,80)), @"the v5 .frame = %@",NSStringFromCGRect(v5.frame));
}

if (1){
Expand Down Expand Up @@ -654,10 +654,10 @@ -(void)testFillAndStretch

XCTAssertTrue(CGRectEqualToRect(rootLayout.frame, CGRectMake(0,0,400,190)), @"the rootLayout.frame = %@",NSStringFromCGRect(rootLayout.frame));

XCTAssertTrue(CGRectEqualToRect(v1.frame, CGRectMake(10,20,35,140)), @"the v1.frame = %@",NSStringFromCGRect(v1.frame));
XCTAssertTrue(CGRectEqualToRect(v2.frame, CGRectMake(45,100,127.5,50)), @"the v2.frame = %@",NSStringFromCGRect(v2.frame));
XCTAssertTrue(CGRectEqualToRect(v3.frame, CGRectMake(172.5,55,40,70)), @"the v3.frame = %@",NSStringFromCGRect(v3.frame));
XCTAssertTrue(CGRectEqualToRect(v4.frame, CGRectMake(212.5,40,127.5,100)), @"the v4 .frame = %@",NSStringFromCGRect(v4.frame));
XCTAssertTrue(CGRectEqualToRect(v1.frame, CGRectMake(10,20,120,140)), @"the v1.frame = %@",NSStringFromCGRect(v1.frame));
XCTAssertTrue(CGRectEqualToRect(v2.frame, CGRectMake(130,100,85,50)), @"the v2.frame = %@",NSStringFromCGRect(v2.frame));
XCTAssertTrue(CGRectEqualToRect(v3.frame, CGRectMake(215,55,40,70)), @"the v3.frame = %@",NSStringFromCGRect(v3.frame));
XCTAssertTrue(CGRectEqualToRect(v4.frame, CGRectMake(255,40,85,100)), @"the v4 .frame = %@",NSStringFromCGRect(v4.frame));
XCTAssertTrue(CGRectEqualToRect(v5.frame, CGRectMake(340,10,40,80)), @"the v5 .frame = %@",NSStringFromCGRect(v5.frame));
}

Expand Down

0 comments on commit 01c88a9

Please sign in to comment.