错误如下:
2019-09-10 15:42:33.583 TestMarsony[1880:547903] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<MASLayoutConstraint:0x13e54d9f0 UILabel:0x13e54ac10.height == 48>",
"<MASLayoutConstraint:0x13e54d990 UILabel:0x13e54ac10.top == HCHelpDetailTextView:0x13e5383d0.top + 10>",
"<MASLayoutConstraint:0x13e54e130 UILabel:0x13e54c150.top == UILabel:0x13e54ac10.bottom + 10>",
"<MASLayoutConstraint:0x13e54e390 UILabel:0x13e54c150.bottom == HCHelpDetailTextView:0x13e5383d0.bottom>",
"<NSAutoresizingMaskLayoutConstraint:0x13e6c8e30 HCHelpDetailTextView:0x13e5383d0.height == 0>"
)
Will attempt to recover by breaking constraint
<MASLayoutConstraint:0x13e54d9f0 UILabel:0x13e54ac10.height == 48>
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.
2019-09-10 15:42:33.584 TestMarsony[1880:547903] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<MASLayoutConstraint:0x13e54d990 UILabel:0x13e54ac10.top == HCHelpDetailTextView:0x13e5383d0.top + 10>",
"<MASLayoutConstraint:0x13e54e130 UILabel:0x13e54c150.top == UILabel:0x13e54ac10.bottom + 10>",
"<MASLayoutConstraint:0x13e54e390 UILabel:0x13e54c150.bottom == HCHelpDetailTextView:0x13e5383d0.bottom>",
"<NSAutoresizingMaskLayoutConstraint:0x13e6c8e30 HCHelpDetailTextView:0x13e5383d0.height == 0>"
)
Will attempt to recover by breaking constraint
<MASLayoutConstraint:0x13e54e130 UILabel:0x13e54c150.top == UILabel:0x13e54ac10.bottom + 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.
原因之一
在某view内部,使用了限定。但是该view本身没有设置frame。即会报该错误。
举例:
有一个view类HCHelpDetailTextView,里面有两个label使用了限定。
代码如下:
- (id)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if( self ){
_titleL = [UILabel new];
[self addSubview:_titleL];
_contentL = [UILabel new];
[self addSubview:_contentL];
[_titleL mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(0);
make.top.mas_equalTo(10);
make.height.mas_equalTo(48);
}];
[_contentL mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(0);
make.top.mas_equalTo(self.titleL.mas_bottom).mas_offset(10);
make.bottom.mas_equalTo(self.mas_bottom).mas_offset(0);
}];
}
return self;
}
在viewController里调用,如下
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
HCHelpDetailTextView *tv = [HCHelpDetailTextView new];
// tv.frame = CGRectMake(0, 0, 100, 230);
[self.view addSubview:tv];
}
如果不设置tv.frame 则即会报上面的问题。设置了则不会报。
解决方案:
设置该view的translatesAutoresizingMaskIntoConstraints 属性为NO
[tv setTranslatesAutoresizingMaskIntoConstraints:NO];
对于该属性的详情,请参考
https://blog.csdn.net/u010140921/article/details/40627983
网友评论