問題:this
約束警告:Unable to simultaneously satisfy constraints.debug
Probably at least one of the constraints in the following list is one you don't want. code
Try this: it
(1) look at each constraint and try to figure out which you don't expect; ast
(2) find the code that added the unwanted constraint or constraints and fix it. tls
(sed
"<MASLayoutConstraint:0x7fa1e4f39270 UIView:0x7fa1e5007170.left == UIView:0x7fa1e519a300.left + 10>",bug
"<MASLayoutConstraint:0x7fa1e4f39ae0 UIView:0x7fa1e5007170.right == UIView:0x7fa1e519a300.right - 10>",im
"<NSLayoutConstraint:0x7fa1e25a2130 UIView:0x7fa1e519a300.width == 0>"nw
)
Will attempt to recover by breaking constraint
<MASLayoutConstraint:0x7fa1e4f39ae0 UIView:0x7fa1e5007170.right == UIView:0x7fa1e519a300.right - 10>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
code:
-(UIView *)createFooterView{
UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50.f)];
[view setBackgroundColor:[UIColor whiteColor]];
UIView * lineView = [[UIView alloc]init];
[view addSubview:lineView];
[lineView makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(view.centerY);
make.left.equalTo(view.left).offset(10);
make.right.equalTo(view.right).offset(-10); //此行與下行的比較 這麼寫不警告
// make.width.equalTo(SCREEN_WIDTH -w 20); //這麼寫 就有以上警告
make.height.equalTo(1.f);
}];
[lineView setBackgroundColor:[CommUtls colorWithHexString:@"#cecece"]];
UILabel * label = [[UILabel alloc]init];
[view addSubview:label];
[label setText:@" 已經到底部了 "];
[label makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(lineView.centerY);
make.centerX.equalTo(lineView.centerX);
}];
[label setFont:[UIFont systemFontOfSize:13.f]];
[label setTextColor:[CommUtls colorWithHexString:@"0x666666"]];
[label setBackgroundColor:[UIColor whiteColor]];
return view;
}
總結:將一個view賦給另個View時 未知寬度 左右約束 產生警告 ,控制寬度便可