Skip to content

Commit

Permalink
功能升级,BUG修复。
Browse files Browse the repository at this point in the history
  • Loading branch information
oubaiquan committed Nov 14, 2019
1 parent c103e2f commit 2953028
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 35 deletions.
2 changes: 2 additions & 0 deletions MyLayout/Lib/MyRelativeLayout.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ -(CGSize)calcLayoutSize:(CGSize)size isEstimate:(BOOL)isEstimate pHasSubLayout:(
sbvmyFrame.sizeClass = [sbv myBestSizeClass:sizeClass myFrame:sbvmyFrame];
}
}
else
[sbvmyFrame reset];
}
else
{
Expand Down
58 changes: 35 additions & 23 deletions MyLayoutDemo/AllTestExampleViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -232,33 +232,45 @@ -(void)example4

-(void)example5
{
MyLinearLayout *rootLayout = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Vert];
MyRelativeLayout *rootLayout = [MyRelativeLayout new];
rootLayout.myHeight = MyLayoutSize.wrap;
rootLayout.myHorzMargin = 0;
rootLayout.tag = 100;
[self.view addSubview:rootLayout];
rootLayout.padding = UIEdgeInsetsMake(12, 12, 12, 12);

// UIView * v = [UIView new];
// v.mySize = CGSizeMake(100, 100);
// [rootLayout addSubview:v];
MyLinearLayout *headerLayout = [MyLinearLayout linearLayoutWithOrientation:(MyOrientation_Horz)];
headerLayout.topPos.equalTo(rootLayout.topPos);
headerLayout.leftPos.equalTo(rootLayout.leftPos);
headerLayout.wrapContentHeight = YES;
[rootLayout addSubview:headerLayout];

MyLinearLayout *v = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Vert];
v.tag = 200;
v.hidden = YES;
v.backgroundColor = [UIColor redColor];
v.mySize = CGSizeMake(100, 100);
// v.myHorzMargin = 0;
// v.myHeight = 100;
[rootLayout addSubview:v];
UIImageView *headerView = UIImageView.alloc.init;
headerView.mySize = CGSizeMake(32, 32);
[headerLayout addSubview:headerView];

UILabel *nameLabel = [UILabel new];
nameLabel.text = @"欧阳大哥";
nameLabel.mySize = CGSizeMake(MyLayoutSize.wrap, MyLayoutSize.wrap);
nameLabel.alignment = MyGravity_Vert_Center;
nameLabel.myLeft = 5;
[headerLayout addSubview:nameLabel];

UILabel *titleLabel = [UILabel new];
titleLabel.text = @"大师傅阿萨德阿斯蒂芬阿斯蒂芬";
titleLabel.myHeight = MyLayoutSize.wrap;
titleLabel.leftPos.equalTo(headerLayout.leftPos).offset(32 + 5);
titleLabel.topPos.equalTo(headerLayout.bottomPos).offset(5);
titleLabel.rightPos.equalTo(rootLayout.rightPos);
[rootLayout addSubview:titleLabel];

MyLinearLayout *barView = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Horz];
barView.myHeight = 20;
barView.leftPos.equalTo(titleLabel.leftPos);
barView.rightPos.equalTo(rootLayout.rightPos);
barView.topPos.equalTo(titleLabel.bottomPos);
[rootLayout addSubview:barView];

[self.view addSubview:rootLayout];

[NSTimer scheduledTimerWithTimeInterval:30 repeats:NO block:^(NSTimer * _Nonnull timer) {

v.hidden = NO;

// UIView *vv1 = [UIView new];
// vv1.mySize = CGSizeMake(100, 100);
// [v addSubview:vv1];

}];
}

@end
24 changes: 12 additions & 12 deletions MyLayoutTests/MyFlowLayoutTestCase.m
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ -(void)testFlex1
//测试内容约束布局下的尺寸自适应,以及最大最小值设置的场景。

{
MyFlexLayout *flexLayout = MyFlexLayout.new.flex
MyFlexLayout *flexLayout = MyFlexLayout.new.myFlex
.align_items(MyFlexGravity_Center)
.justify_content(MyFlexGravity_Center)
.margin(0)
Expand All @@ -1115,7 +1115,7 @@ -(void)testFlex1
flexLayout.backgroundColor = [UIColor redColor];


MyFlexLayout *contentLayout = MyFlexLayout.new.flex
MyFlexLayout *contentLayout = MyFlexLayout.new.myFlex
.flex_wrap(MyFlexWrap_Wrap)
.width(MyLayoutSize.wrap)
.max_width(100)
Expand All @@ -1124,21 +1124,21 @@ -(void)testFlex1

contentLayout.backgroundColor = [UIColor greenColor];

UILabel *lb1 = UILabel.new.flexItem
UILabel *lb1 = UILabel.new.myFlex
.width(30)
.height(30)
.addTo(contentLayout);

lb1.backgroundColor = [UIColor blueColor];

UILabel *lb2 = UILabel.new.flexItem
UILabel *lb2 = UILabel.new.myFlex
.width(40)
.height(40)
.addTo(contentLayout);

lb2.backgroundColor = [UIColor yellowColor];

UILabel *lb3 = UILabel.new.flexItem
UILabel *lb3 = UILabel.new.myFlex
.width(50)
.height(50)
.addTo(contentLayout);
Expand All @@ -1151,7 +1151,7 @@ -(void)testFlex1
MyRectAssert(contentLayout, CGRectMake((300-100)/2.0, (300-90)/2.0, 100, 90));
MyRectAssert(lb3, CGRectMake(0, 40, 50, 50));

contentLayout.flex.height(30);
contentLayout.myFlex.height(30);
[flexLayout setNeedsLayout];
[contentLayout setNeedsLayout];
[contentLayout layoutIfNeeded];
Expand All @@ -1163,7 +1163,7 @@ -(void)testFlex1
}

{
MyFlexLayout *flexLayout = MyFlexLayout.new.flex
MyFlexLayout *flexLayout = MyFlexLayout.new.myFlex
.align_items(MyFlexGravity_Center)
.justify_content(MyFlexGravity_Center)
.margin(0)
Expand All @@ -1173,7 +1173,7 @@ -(void)testFlex1
flexLayout.backgroundColor = [UIColor redColor];


MyFlexLayout *contentLayout = MyFlexLayout.new.flex
MyFlexLayout *contentLayout = MyFlexLayout.new.myFlex
.flex_wrap(MyFlexWrap_Wrap)
.flex_direction(MyFlexDirection_Column)
.width(MyLayoutSize.wrap)
Expand All @@ -1183,21 +1183,21 @@ -(void)testFlex1

contentLayout.backgroundColor = [UIColor greenColor];

UILabel *lb1 = UILabel.new.flexItem
UILabel *lb1 = UILabel.new.myFlex
.width(30)
.height(30)
.addTo(contentLayout);

lb1.backgroundColor = [UIColor blueColor];

UILabel *lb2 = UILabel.new.flexItem
UILabel *lb2 = UILabel.new.myFlex
.width(40)
.height(40)
.addTo(contentLayout);

lb2.backgroundColor = [UIColor yellowColor];

UILabel *lb3 = UILabel.new.flexItem
UILabel *lb3 = UILabel.new.myFlex
.width(50)
.height(50)
.addTo(contentLayout);
Expand All @@ -1210,7 +1210,7 @@ -(void)testFlex1
MyRectAssert(contentLayout, CGRectMake((300-90)/2.0,(300-100)/2.0,90,100));
MyRectAssert(lb3, CGRectMake(40, 0, 50, 50));

contentLayout.flex.width(30);
contentLayout.myFlex.width(30);
[flexLayout setNeedsLayout];
[contentLayout setNeedsLayout];
[contentLayout layoutIfNeeded];
Expand Down
43 changes: 43 additions & 0 deletions MyLayoutTests/MyRelativeLayoutTestCase.m
Original file line number Diff line number Diff line change
Expand Up @@ -1389,6 +1389,49 @@ -(void)testExample1
XCTAssertTrue(CGRectEqualToRect(v7.frame, CGRectMake(0,-16,100,100)), @"the v7.frame = %@",NSStringFromCGRect(v7.frame));
}

-(void)testWrapContentHeight4
{
MyRelativeLayout *rootLayout = [MyRelativeLayout new];
rootLayout.myHeight = MyLayoutSize.wrap;
rootLayout.padding = UIEdgeInsetsMake(12, 12, 12, 12);

MyLinearLayout *headerLayout = [MyLinearLayout linearLayoutWithOrientation:(MyOrientation_Horz)];
headerLayout.topPos.equalTo(rootLayout.topPos);
headerLayout.leftPos.equalTo(rootLayout.leftPos);
headerLayout.wrapContentHeight = YES;
[rootLayout addSubview:headerLayout];

UIImageView *headerView = UIImageView.alloc.init;
headerView.mySize = CGSizeMake(32, 32);
[headerLayout addSubview:headerView];

UILabel *nameLabel = [UILabel new];
nameLabel.text = @"欧阳大哥";
nameLabel.mySize = CGSizeMake(MyLayoutSize.wrap, MyLayoutSize.wrap);
nameLabel.alignment = MyGravity_Vert_Center;
nameLabel.myLeft = 5;
[headerLayout addSubview:nameLabel];

UILabel *titleLabel = [UILabel new];
titleLabel.text = @"大师傅阿萨德阿斯蒂芬阿斯蒂芬";
titleLabel.myHeight = MyLayoutSize.wrap;
titleLabel.leftPos.equalTo(headerLayout.leftPos).offset(32 + 5);
titleLabel.topPos.equalTo(headerLayout.bottomPos).offset(5);
titleLabel.rightPos.equalTo(rootLayout.rightPos);
[rootLayout addSubview:titleLabel];

MyLinearLayout *barView = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Horz];
barView.myHeight = 20;
barView.leftPos.equalTo(titleLabel.leftPos);
barView.rightPos.equalTo(rootLayout.rightPos);
barView.topPos.equalTo(titleLabel.bottomPos);
[rootLayout addSubview:barView];

CGSize sz = [rootLayout sizeThatFits:CGSizeMake(375, 0)];
MySizeAssert(rootLayout,sz,CGSizeMake(375, 101.5));
//MyRectAssert(rootLayout, CGRectMake(0, 0, sz.width, sz.height));
}

- (void)testPerformanceExample {
// This is an example of a performance test case.
[self measureBlock:^{
Expand Down

0 comments on commit 2953028

Please sign in to comment.