iPhone X safeArea self.view.mas_safeAreaLayoutGuide crash
New Issue Checklist
🚫 If this template is not filled out your issue will be closed with no comment. 🚫
- [x] I have looked at the Documentation
- [x] I have filled out this issue template.
Issue Info
| Info | Value |
|---|---|
| Platform | e.g. ios |
| Platform Version | e.g. 11.1 |
| Masonry Version | e.g. 1.1.0 |
| Integration Method | e.g. carthage/cocoapods/manually |
Issue Description
[self.testView mas_remakeConstraints:^(MASConstraintMaker *make) {
if (@available(iOS 11.0, *)) {
//crash
// make.edges.equalTo(self.view.mas_safeAreaLayoutGuide);
//ok
make.left.equalTo(self.view.mas_safeAreaLayoutGuideLeft);
make.right.equalTo(self.view.mas_safeAreaLayoutGuideRight);
make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop);
make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
} else {
make.edges.equalTo(self.view);
}
}];
please tell me why this code crash when use make.edges.equalTo(self.view.mas_safeAreaLayoutGuide);
crash log
2017-11-09 15:47:32.383071+0800 iPhoneXDemo[4397:2026018] *** Terminating app due to uncaught exception 'NSInvalidLayoutConstraintException', reason: 'Constraint improperly relates anchors of incompatible types: <MASLayoutConstraint:0x1d00bcec0 UIView:0x11bd05a70.left == UILayoutGuide:0x1d01ae460.bottom>'
*** First throw call stack:
(0x185769d04 0x1849b8528 0x185769c4c 0x18617489c 0x18609bdac 0x18609ba04 0x18ec898e4 0x18ec896c0 0x1001681bc 0x10015fa78 0x100163228 0x10016d688 0x10015cda4 0x18eba0f08 0x18ec485f8 0x18ec47a98 0x18ec4749c 0x18ec46f18 0x18ec46e18 0x18eb9e304 0x189757ec8 0x18975bfa8 0x1896caa98 0x1896f0eb4 0x18ee1c180 0x1857120fc 0x1857119cc 0x18570f6dc 0x18562ffb8 0x1874c7f84 0x18ec042f4 0x10015d1f8 0x18515256c)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Same here!
same here; why demo is ok?
When using leading and trailing it crashes (left and right are ok). I guess this is why using edges crashes too as it'll translate to use leading and trailing
//crash make.leading.equalTo(self.view.mas_safeAreaLayoutGuideLeft); make.trailing.equalTo(self.view.mas_safeAreaLayoutGuideRight); make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop); make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
//ok make.left.equalTo(self.view.mas_safeAreaLayoutGuideLeft); make.right.equalTo(self.view.mas_safeAreaLayoutGuideRight); make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop); make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
Strangely, just mas_safeAreaLayoutGuide is mapped to bottom. Also, leading and trailing are missing
Turns out, I was using an older version. Leading and Trailing are there now, so you should use something like:
make.top.equalTo(self.contentView.mas_safeAreaLayoutGuideTop).with.insets(margins);
make.leading.equalTo(self.contentView.mas_safeAreaLayoutGuideLeading).with.insets(margins);
make.trailing.equalTo(self.contentView.mas_safeAreaLayoutGuideTrailing).with.insets(margins);
make.bottom.equalTo(self.contentView.mas_safeAreaLayoutGuideBottom).with.insets(margins);
The regular mas_safeAreaLayoutGuide doesn't seem to work if you want to use the shorthand edges.equalTo